Skip to content
Snippets Groups Projects
Commit 4b1afbab authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Merge branch '1073720_FixOrderSalesProjectPresetAndhelperFunctionsForContactTypes' into '2021.0'

1073720 fix order sales project preset andhelper functions for contact types

See merge request xrm/basic!761
parents 6f85aabe 5b6e3a44
No related branches found
No related tags found
No related merge requests found
...@@ -8,13 +8,13 @@ import("Entity_lib"); ...@@ -8,13 +8,13 @@ import("Entity_lib");
import("Contact_lib"); import("Contact_lib");
import("system.datetime"); import("system.datetime");
var contactid = vars.get("$local.value"); var contactId = vars.get("$local.value");
if(contactid != "") if(contactId != "")
{ {
//Language Preset //Language Preset
var lang = newSelect("ISOLANGUAGE") var lang = newSelect("ISOLANGUAGE")
.from("CONTACT") .from("CONTACT")
.where("CONTACT.CONTACTID", contactid) .where("CONTACT.CONTACTID", contactId)
.cell(); .cell();
if(lang != "") if(lang != "")
{ {
...@@ -22,30 +22,41 @@ if(contactid != "") ...@@ -22,30 +22,41 @@ if(contactid != "")
} }
//Address Preset //Address Preset
var defaultAddressId = ContactUtils.getDefaultAddressId(contactid); var defaultAddressId = ContactUtils.getDefaultAddressId(contactId);
if (defaultAddressId) if (defaultAddressId)
{ {
neon.setFieldValue("$field.ChosenAddress", defaultAddressId); neon.setFieldValue("$field.ChosenAddress", defaultAddressId);
neon.setFieldValue("$field.ADDRESS", AddressUtils.getAddressById(defaultAddressId)); neon.setFieldValue("$field.ADDRESS", AddressUtils.getAddressById(defaultAddressId));
} }
var addrobj = new AddrObject(contactid); var addrobj = new AddrObject(contactId);
var salutation = addrobj.getFormattedAddress(false, "{letter_salutation},"); var salutation = addrobj.getFormattedAddress(false, "{letter_salutation},");
if (salutation != "Err.,") if (salutation != "Err.,")
{ {
neon.setFieldValue("field.LETTERSALUTATION", salutation); neon.setFieldValue("field.LETTERSALUTATION", salutation);
} }
// set $field.CONTATCT_ORG_ID per contactid // set $field.CONTATCT_ORG_ID per contactId
var orgid = ContactUtils.getPersOrgIds(contactid); var orgid = ContactUtils.getPersOrgIds(contactId);
neon.setFieldValue("$field.CONTACT_ORG_ID", orgid[2]); neon.setFieldValue("$field.CONTACT_ORG_ID", orgid[2]);
//Salesproject Preset //Salesproject Preset
if(vars.get("$field.OBJECT_TYPE") == "Salesproject") if(vars.get("$field.OBJECT_TYPE") == "Salesproject")
{ {
var today = datetime.today();
if(ContactUtils.isPersonOfOrganisation(contactId))//change contactId to contactId of organisation if needed
{
contactId = newSelect("CONTACT.CONTACTID")
.from("CONTACT")
.where("CONTACT.ORGANISATION_ID", newSelect("CONTACT.ORGANISATION_ID")
.from("CONTACT")
.where("CONTACT.CONTACTID", contactId)
.cell())
.and("CONTACT.PERSON_ID is null")
.cell();
}
var salesProjectId = newSelect("SALESPROJECT.SALESPROJECTID") var salesProjectId = newSelect("SALESPROJECT.SALESPROJECTID")
.from("SALESPROJECT") .from("SALESPROJECT")
.where("SALESPROJECT.CONTACT_ID", contactid) .where("SALESPROJECT.CONTACT_ID", contactId)
.cell(); .cell();
if(salesProjectId) if(salesProjectId)
{ {
......
...@@ -18,7 +18,9 @@ if(contactId != "") ...@@ -18,7 +18,9 @@ if(contactId != "")
.where("CONTACT.CONTACTID", contactId) .where("CONTACT.CONTACTID", contactId)
.cell(); .cell();
if(lang != "") if(lang != "")
{
neon.setFieldValue("field.ISOLANGUAGE", lang); neon.setFieldValue("field.ISOLANGUAGE", lang);
}
//Address Preset //Address Preset
var defaultAddressId = ContactUtils.getDefaultAddressId(contactId); var defaultAddressId = ContactUtils.getDefaultAddressId(contactId);
...@@ -30,6 +32,19 @@ if(contactId != "") ...@@ -30,6 +32,19 @@ if(contactId != "")
neon.setFieldValue("$field.DELIVERYADDRESS", AddressUtils.getAddressById(defaultAddressId)); neon.setFieldValue("$field.DELIVERYADDRESS", AddressUtils.getAddressById(defaultAddressId));
} }
var cond;hal
if(ContactUtils.isPersonOfOrganisation(contactId))//change contactId to contactId of organisation if needed
{
contactId = newSelect("CONTACT.CONTACTID")
.from("CONTACT")
.where("CONTACT.ORGANISATION_ID", newSelect("CONTACT.ORGANISATION_ID")
.from("CONTACT")
.where("CONTACT.CONTACTID", contactId)
.cell())
.and("CONTACT.PERSON_ID is null")
.cell();
}
//Salesproject Preset //Salesproject Preset
var today = datetime.today(); var today = datetime.today();
var salesProjectId = newSelect("SALESPROJECT.SALESPROJECTID") var salesProjectId = newSelect("SALESPROJECT.SALESPROJECTID")
...@@ -37,5 +52,7 @@ if(contactId != "") ...@@ -37,5 +52,7 @@ if(contactId != "")
.where("SALESPROJECT.CONTACT_ID", contactId) .where("SALESPROJECT.CONTACT_ID", contactId)
.cell(); .cell();
if(salesProjectId) if(salesProjectId)
{
neon.setFieldValue("$field.OBJECT_ROWID", salesProjectId); neon.setFieldValue("$field.OBJECT_ROWID", salesProjectId);
}
} }
\ No newline at end of file
import("Contact_lib"); import("Contact_lib");
import("Sql_lib");
import("system.logging");
import("system.neon"); import("system.neon");
import("system.result"); import("system.result");
import("system.vars"); import("system.vars");
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && (vars.get("$this.value") == null || vars.get("$this.value") == undefined)) if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && (vars.get("$this.value") == null || vars.get("$this.value") == undefined))
{ {
var isPersonContact = newSelect("PERSON.PERSONID").from("PERSON") if(!ContactUtils.isOrganisation(vars.get("$param.ContactId_param")))
.join("CONTACT", "PERSON.PERSONID = CONTACT.PERSON_ID")
.whereIfSet("CONTACT.CONTACTID", vars.get("$param.ContactId_param")).cell()
if(isPersonContact)
{ {
result.string(vars.get("$param.ContactId_param")); result.string(vars.get("$param.ContactId_param"));
} }
......
...@@ -130,9 +130,9 @@ ContactUtils.validateIfAlreadyExists = function(pPersonId, pOrganisationId, pOwn ...@@ -130,9 +130,9 @@ ContactUtils.validateIfAlreadyExists = function(pPersonId, pOrganisationId, pOwn
/** /**
* Get the type of contact. <br> * Get the type of contact. <br>
* In recordstate NEW or EDIT it loads the person- / orgid from the db.<br> * In recordstate NEW or EDIT it loads the person- / orgid from the db.<br>
* But in the other states it uses the values pPersId, pOrgId directly (for performance).<br> * But in the other states it uses the values pPersonId, pOrganisationId directly (for performance).<br>
* <br> * <br>
* It only checks if pPersId / pOrgId are not empty. <br> * It only checks if pPersonId / pOrganisationId are not empty. <br>
* Based on which parameter is empty / not empty it return s the type of the contact. <br> * Based on which parameter is empty / not empty it return s the type of the contact. <br>
* <br> * <br>
* !!It does not check if the person / org ids really exist!! <br> * !!It does not check if the person / org ids really exist!! <br>
...@@ -144,15 +144,15 @@ ContactUtils.validateIfAlreadyExists = function(pPersonId, pOrganisationId, pOwn ...@@ -144,15 +144,15 @@ ContactUtils.validateIfAlreadyExists = function(pPersonId, pOrganisationId, pOwn
* <br> * <br>
* <br> * <br>
* @param {String} pContactId * @param {String} pContactId
* @param {String} pPersId selected from the CONTACT table * @param {String} pPersonId selected from the CONTACT table
* @param {String} pOrgId selected from the CONTACT table * @param {String} pOrganisationId selected from the CONTACT table
* <br> * <br>
* @return {Integer} <br>0 if both ids are empty <br> * @return {Integer} <br>0 if both ids are empty <br>
* 1 if organisation <br> * 1 if organisation <br>
* 2 if privat person <br> * 2 if privat person <br>
* 3 if person of an organisation <br> * 3 if person of an organisation <br>
*/ */
ContactUtils.getContactType = function(pContactId, pPersId, pOrgId) ContactUtils.getContactType = function(pContactId, pPersonId, pOrganisationId)
{ {
if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT) if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.recordstate") == neon.OPERATINGSTATE_EDIT)
{ {
...@@ -160,10 +160,70 @@ ContactUtils.getContactType = function(pContactId, pPersId, pOrgId) ...@@ -160,10 +160,70 @@ ContactUtils.getContactType = function(pContactId, pPersId, pOrgId)
} }
else else
{ {
return ContactUtils.getContactTypeByPersOrg(pPersId, pOrgId); return ContactUtils.getContactTypeByPersOrg(pPersonId, pOrganisationId);
} }
} }
/**
* Check if the contact is of the contactType "1": organisation <br>
* This function uses "ContactUtils.getContactType" to check the type.<br>
* So for more information about when to use whcih parameters for better perfrmance see it's documentation.<br>
* <br>
* <br>
* @param {String} pContactId
* @param {String} pPersonId selected from the CONTACT table
* @param {String} pOrganisationId selected from the CONTACT table
* <br>
* @return {Boolean} <br>true if the contact is a organisationType<br>
* else: false <br>
*/
ContactUtils.isOrganisation = function(pContactId, pPersonId, pOrganisationId)
{
var contactType = ContactUtils.getContactType(pContactId, pPersonId, pOrganisationId);
return contactType == 1;
}
/**
* Check if the contact is of the contactType "2": private person <br>
* This function uses "ContactUtils.getContactType" to check the type.<br>
* So for more information about when to use whcih parameters for better perfrmance see it's documentation.<br>
* <br>
* <br>
* @param {String} pContactId
* @param {String} pPersonId selected from the CONTACT table
* @param {String} pOrganisationId selected from the CONTACT table
* <br>
* @return {Boolean} <br>true if the contact is a private person<br>
* else: false <br>
*/
ContactUtils.isPrivatePerson = function(pContactId, pPersonId, pOrganisationId)
{
var contactType = ContactUtils.getContactType(pContactId, pPersonId, pOrganisationId);
return contactType == 2;
}
/**
* Check if the contact is of the contactType "3": person of an organisation <br>
* This function uses "ContactUtils.getContactType" to check the type.<br>
* So for more information about when to use whcih parameters for better perfrmance see it's documentation.<br>
* <br>
* <br>
* @param {String} pContactId
* @param {String} pPersonId selected from the CONTACT table
* @param {String} pOrganisationId selected from the CONTACT table
* <br>
* @return {Boolean} <br>true if the contact is a person of an organisation<br>
* else: false <br>
*/
ContactUtils.isPersonOfOrganisation = function(pContactId, pPersonId, pOrganisationId)
{
var contactType = ContactUtils.getContactType(pContactId, pPersonId, pOrganisationId);
return contactType == 3;
}
/** /**
* get the type of contact for a relationId <br> * get the type of contact for a relationId <br>
* If you already have persId and orgId from the CONTACT table, use getContactTypeByPersOrg() <br> * If you already have persId and orgId from the CONTACT table, use getContactTypeByPersOrg() <br>
...@@ -201,26 +261,26 @@ ContactUtils.getContactTypeByContactId = function(pContactId) ...@@ -201,26 +261,26 @@ ContactUtils.getContactTypeByContactId = function(pContactId)
* It is meant to be used by entitys, where you can load person and org with the DataRecord. <br> * It is meant to be used by entitys, where you can load person and org with the DataRecord. <br>
* This saves an extra select from CONTACT. <br> * This saves an extra select from CONTACT. <br>
* <br> * <br>
* @param {String} pPersId selected from the CONTACT table * @param {String} pPersonId selected from the CONTACT table
* @param {String} pOrgId selected from the CONTACT table * @param {String} pOrganisationId selected from the CONTACT table
* <br> * <br>
* @return {Integer} <br>0 if both ids are empty <br> * @return {Integer} <br>0 if both ids are empty <br>
* 1 if organisation <br> * 1 if organisation <br>
* 2 if privat person <br> * 2 if privat person <br>
* 3 if person of an organisation <br> * 3 if person of an organisation <br>
*/ */
ContactUtils.getContactTypeByPersOrg = function(pPersId, pOrgId) ContactUtils.getContactTypeByPersOrg = function(pPersonId, pOrganisationId)
{ {
if (!pPersId) if (!pPersonId)
{ {
if (!pOrgId) { if (!pOrganisationId) {
return 0; // both are empty return 0; // both are empty
} }
return 1; // Organisation da PERSON_ID leer return 1; // Organisation da PERSON_ID leer
} }
else else
{ {
if (pOrgId.replace(/\s/g,"") == "0" ) if (pOrganisationId.replace(/\s/g,"") == "0" )
{ {
return 2; // Privatperson da PERSON_ID nicht leer und ORGANISATION_ID.trim() = '0' return 2; // Privatperson da PERSON_ID nicht leer und ORGANISATION_ID.trim() = '0'
} }
...@@ -247,14 +307,14 @@ ContactUtils.getContactTypeByPersOrg = function(pPersId, pOrgId) ...@@ -247,14 +307,14 @@ ContactUtils.getContactTypeByPersOrg = function(pPersId, pOrgId)
* This saves an extra select from CONTACT. <br> * This saves an extra select from CONTACT. <br>
* <br> * <br>
* *
* @param {String} pPersId selected from the CONTACT table * @param {String} pPersonId selected from the CONTACT table
* @param {String} pOrgId selected from the CONTACT table * @param {String} pOrganisationId selected from the CONTACT table
* *
* @return {String} contextname or "" if both ids are empty * @return {String} contextname or "" if both ids are empty
*/ */
ContactUtils.getContextByPersOrg = function(pPersId, pOrgId) ContactUtils.getContextByPersOrg = function(pPersonId, pOrganisationId)
{ {
switch (ContactUtils.getContactTypeByPersOrg(pPersId, pOrgId)) switch (ContactUtils.getContactTypeByPersOrg(pPersonId, pOrganisationId))
{ {
case 1: // Org case 1: // Org
return ContextUtils.getContextName("Organisation"); return ContextUtils.getContextName("Organisation");
...@@ -329,15 +389,15 @@ ContactUtils.getOrganisationContactId = function(pAnyContactId) ...@@ -329,15 +389,15 @@ ContactUtils.getOrganisationContactId = function(pAnyContactId)
/** /**
* get the contactId from the OrganisationId * get the contactId from the OrganisationId
* *
* @param {String} pOrgId * @param {String} pOrganisationId
* @return {String} the contactId or "" * @return {String} the contactId or ""
*/ */
ContactUtils.getOrgContactId = function(pOrgId) ContactUtils.getOrgContactId = function(pOrganisationId)
{ {
if (pOrgId) { if (pOrganisationId) {
return newSelect("CONTACTID") return newSelect("CONTACTID")
.from("CONTACT") .from("CONTACT")
.where("CONTACT.ORGANISATION_ID", pOrgId) .where("CONTACT.ORGANISATION_ID", pOrganisationId)
.and("CONTACT.PERSON_ID is null") .and("CONTACT.PERSON_ID is null")
.cell(); .cell();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment