diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod index 9d13160611c003b88ae73242968d47e87385e4b7..b28b37030cb44e062296f18b88916ea63b8ab4c0 100644 --- a/entity/Person_entity/Person_entity.aod +++ b/entity/Person_entity/Person_entity.aod @@ -1389,6 +1389,9 @@ <name>LETTERSALUTATION</name> <title>Lettersalutation</title> </entityField> + <entityField> + <name>contenttitle</name> + </entityField> </entityFields> <recordContainers> <dbRecordContainer> @@ -1697,6 +1700,10 @@ <name>LETTERSALUTATION.value</name> <recordfield>CONTACT.LETTERSALUTATION</recordfield> </dbRecordFieldMapping> + <dbRecordFieldMapping> + <name>contenttitle.value</name> + <expression>%aditoprj%/entity/Person_entity/recordcontainers/db/recordfieldmappings/contenttitle.value/expression.js</expression> + </dbRecordFieldMapping> </recordFieldMappings> <linkInformation> <linkInformation> diff --git a/entity/Person_entity/contentTitleProcess.js b/entity/Person_entity/contentTitleProcess.js index 68305e82bfdac45f9d0e8f2f92c77e6a01b1b6de..4377860159677ac5ec536efc7618c0657d1372ff 100644 --- a/entity/Person_entity/contentTitleProcess.js +++ b/entity/Person_entity/contentTitleProcess.js @@ -1,16 +1,4 @@ import("system.vars"); import("system.result"); -import("Util_lib"); -import("Contact_lib"); -//do not use "FULL_NAME_fieldGroup" here since the field group must not include the orgname -var contact = new Contact(); -contact.salutation = vars.get("$field.SALUTATION"); -contact.title = vars.get("$field.TITLE"); -contact.firstname = vars.get("$field.FIRSTNAME"); -contact.middlename = vars.get("$field.MIDDLENAME"); -contact.lastname = vars.get("$field.LASTNAME"); -contact.organisationName = vars.get("$field.ORGANISATION_NAME"); - -var renderer = new ContactTitleRenderer(contact, null); -result.string(renderer.asString()); \ No newline at end of file +result.string(vars.get("$field.contenttitle")); \ No newline at end of file diff --git a/entity/Person_entity/entityfields/full_name_fieldgroup/valueProcess.js b/entity/Person_entity/entityfields/full_name_fieldgroup/valueProcess.js index 778c203ff13f6bc2955db27cc8c7ec6544de380d..07e52e7b7e19bc619a6949f01cc2a1b9dfabf8d3 100644 --- a/entity/Person_entity/entityfields/full_name_fieldgroup/valueProcess.js +++ b/entity/Person_entity/entityfields/full_name_fieldgroup/valueProcess.js @@ -1,15 +1,4 @@ import("system.vars"); import("system.result"); -import("Util_lib"); -import("Contact_lib"); -//no orgname here since the org-field is in the card-template as separate field -var contact = new Contact(); -contact.salutation = vars.get("$field.SALUTATION"); -contact.title = vars.get("$field.TITLE"); -contact.firstname = vars.get("$field.FIRSTNAME"); -contact.middlename = vars.get("$field.MIDDLENAME"); -contact.lastname = vars.get("$field.LASTNAME"); - -var renderer = new ContactTitleRenderer(contact, null); -result.string(renderer.asString()); \ No newline at end of file +result.string(vars.get("$field.contenttitle")); \ No newline at end of file diff --git a/entity/Person_entity/recordcontainers/db/recordfieldmappings/contenttitle.value/expression.js b/entity/Person_entity/recordcontainers/db/recordfieldmappings/contenttitle.value/expression.js new file mode 100644 index 0000000000000000000000000000000000000000..89a6fc8ad6892d6f536e7887086fe7b24d323cbe --- /dev/null +++ b/entity/Person_entity/recordcontainers/db/recordfieldmappings/contenttitle.value/expression.js @@ -0,0 +1,4 @@ +import("Contact_lib"); +import("system.result"); + +result.string(ContactUtils.getContactSalutationSubSql(true)); \ No newline at end of file diff --git a/process/Contact_lib/process.js b/process/Contact_lib/process.js index ef75d00d32dd94fd8827b744714cd84fa65e7ba7..e62bcfe34e30642c47b40f43c61f103a1ee99878 100644 --- a/process/Contact_lib/process.js +++ b/process/Contact_lib/process.js @@ -798,6 +798,53 @@ ContactUtils.isDeletable = function (pCurrentContext, pContactId, pPersonId) .validate(); } +/** + * Gives the contenttitle in right order from salutaion as SubSQL + * + * @param {Boolean} pGetHeadline if you want SALUTATION.HEADLINE as COLUMN + * @param {Boolean} pGetLetterSalutation if you want SALUTATION.LETTERSALUTATION as COLUMN + * + * @return {String} Subsql for DB.expression + */ +ContactUtils.getContactSalutationSubSql = function(pGetHeadline, pGetLetterSalutation) +{ + var column; + if(pGetHeadline) + { + column = "SALUTATION.HEADLINE"; + } + if(pGetLetterSalutation) + { + column = "SALUTATION.LETTERSALUTATION"; + } + var sqlHelper = new SqlMaskingUtils(); + var personSelect = ""; + var orgSelect = column; + var saltuationPlaceholders = {"'{fn}'": "PERSON.FIRSTNAME", "'{ln}'": "PERSON.LASTNAME", "'{ti}'": "PERSON.TITLE"}; + Object.keys(saltuationPlaceholders).forEach(function(placeholder){ + let persSelectFront = "REPLACE("; + let persSelectBack = ", " + placeholder + ", " + sqlHelper.isNull(saltuationPlaceholders[placeholder], "''") + ")"; + if(!personSelect) + { + personSelect = persSelectFront + column + persSelectBack; + } + else + { + personSelect = persSelectFront + personSelect + persSelectBack; + } + }); + var saltuation = newSelect("case when CONTACT.PERSON_ID is null then " + orgSelect + " else " + personSelect + "end") + .from("SALUTATION") + .where("SALUTATION.ISOLANGUAGE = CONTACT.ISOLANGUAGE") + .and(newWhere("SALUTATION.SEX = PERSON.GENDER").or("SALUTATION.SEX is null")) + .and(newWhere("SALUTATION.TITLE = PERSON.TITLE").or("SALUTATION.TITLE is null")) + .and(newWhere("SALUTATION.SALUTATION = PERSON.SALUTATION").or("SALUTATION.SALUTATION is null")) + .orderBy("SALUTATION.SEX desc, SALUTATION.TITLE desc"); + saltuation = saltuation.toString(); + saltuation = saltuation + " " + sqlHelper.limit(1); + return saltuation; +} + /** * object for handling of a single contact * provides static- and instance-functions