diff --git a/entity/Offer_entity/entityfields/deliveryterms/valueProcess.js b/entity/Offer_entity/entityfields/deliveryterms/valueProcess.js index 0ae20dad6e06f3bda90fdbff5e7b83a63e5ca241..dbe9f498ff572bb1b9870dd475be5bf2d495793b 100644 --- a/entity/Offer_entity/entityfields/deliveryterms/valueProcess.js +++ b/entity/Offer_entity/entityfields/deliveryterms/valueProcess.js @@ -1,8 +1,10 @@ +import("system.logging"); import("AttributeRegistry_basic"); import("system.neon"); import("system.result"); import("system.vars"); import("Attribute_lib"); +import("Contact_lib"); if (vars.exists("$param.OfferDeliveryTerm_param") && vars.get("$param.OfferDeliveryTerm_param")) { @@ -10,9 +12,13 @@ if (vars.exists("$param.OfferDeliveryTerm_param") && vars.get("$param.OfferDeliv } else if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) { - var contactId = vars.getString("$field.CONTACT_ID"); - if (contactId) - { - result.string(AttributeRelationUtils.getAttribute($AttributeRegistry.deliveryTerm(), contactId)); + var contactIds = ContactUtils.getPersOrgIds(vars.getString("$field.CONTACT_ID")) + if (contactIds.length >= 3 && contactIds[2]) + { + var orgContactId = ContactUtils.getOrgContactId(contactIds[2]); + if (orgContactId) + { + result.string(AttributeRelationUtils.getAttribute($AttributeRegistry.deliveryTerm(), orgContactId)); + } } } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js b/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js index 22a6e045a3a3c037f3081a29d3d34810375564f9..7b92c1bb14aa08001b7d5738111337ab7e81f4cc 100644 --- a/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js +++ b/entity/Offer_entity/entityfields/objects/children/contactid_param/valueProcess.js @@ -1,10 +1,10 @@ -import("system.result"); -import("system.vars"); -import("Contact_lib"); - -if (vars.get("$field.CONTACT_ID")) -{ - var ids = ContactUtils.getPersOrgIds(vars.getString("$field.CONTACT_ID")); - if (ids.length >= 3 && ids[2]) - result.string(ContactUtils.getPersOrgIds(vars.getString("$field.CONTACT_ID"))[2]); +import("system.result"); +import("system.vars"); +import("Contact_lib"); + +if (vars.get("$field.CONTACT_ID")) +{ + var ids = ContactUtils.getPersOrgIds(vars.getString("$field.CONTACT_ID")); + if (ids.length >= 3 && ids[2]) + result.string(ids[2]); } \ No newline at end of file diff --git a/entity/Offer_entity/entityfields/paymentterms/valueProcess.js b/entity/Offer_entity/entityfields/paymentterms/valueProcess.js index e75c10c9751ea47fa79c80841cfc2831dafb2deb..020e52b587cd8ab247a95db399a99b50e9755925 100644 --- a/entity/Offer_entity/entityfields/paymentterms/valueProcess.js +++ b/entity/Offer_entity/entityfields/paymentterms/valueProcess.js @@ -1,3 +1,4 @@ +import("Contact_lib"); import("AttributeRegistry_basic"); import("system.neon"); import("system.result"); @@ -10,9 +11,13 @@ if (vars.exists("$param.OfferPaymentTerm_param") && vars.get("$param.OfferPaymen } else if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW) { - var contactId = vars.getString("$field.CONTACT_ID"); - if (contactId) + var contactIds = ContactUtils.getPersOrgIds(vars.getString("$field.CONTACT_ID")) + if (contactIds.length >= 3 && contactIds[2]) { - result.string(AttributeRelationUtils.getAttribute($AttributeRegistry.paymentTerm(), contactId)); + var orgContactId = ContactUtils.getOrgContactId(contactIds[2]); + if (orgContactId) + { + result.string(AttributeRelationUtils.getAttribute($AttributeRegistry.paymentTerm(), orgContactId)); + } } } \ No newline at end of file diff --git a/process/Contact_lib/process.js b/process/Contact_lib/process.js index 5cca68dfd2b81d5023746b9596a1ca2a1a78baa1..3ea1aece0b5db28903cd7bb956432c8dff4d2e4a 100644 --- a/process/Contact_lib/process.js +++ b/process/Contact_lib/process.js @@ -292,6 +292,24 @@ ContactUtils.getPersOrgIds = function(pContactId) return []; } +/** + * get the contactId from the OrganisationId + * + * @param {String} pOrgId + * @return {String} the contactId or "" + */ +ContactUtils.getOrgContactId = function(pOrgId) +{ + if (pOrgId) { + return db.cell(SqlCondition.begin() + .andPrepare("CONTACT.ORGANISATION_ID", pOrgId) + .and("CONTACT.PERSON_ID is null") + .buildSql("select CONTACTID from CONTACT", "1=0")); + } + + return ""; +} + /** * get the name of the person or organisation *