1

I'm encountering an issue regarding the generation of salutations in message templates. The requirement is to first filter whether the contact is an individual or an organization, specifically focusing on individuals with an employer relationship.

If the address is business-related and the associated employer has filled in custom fields 378 and 379, these fields should be printed in the salutation. Otherwise, the display name of the employer should be used.

Here's the unique aspect: The related tokens plugin (https://github.com/twomice/com.joineryhq.reltoken) provides the ability to retrieve tokens like {related.custom_378___reltype_b_Employee_of_Employer_of}, {related.custom_379___reltype_b_Employee_of_Employer_of}, {related.custom_378___reltype_a_Employee_of_Employer_of}, or {related.custom_378___reltype_a_Employee_of_Employer_of}. These custom fields have been created for some organization contacts to splitt long organization names into two fields.

However, when attempting to access these fields during assignment, a critical error occurs. Could you please assist in resolving this issue? CRM-Version 5.69.0, CMS WordPress 6.4. 3 and PHP 8.1.27.

Thank you.

Here the Code:

{capture assign=typeOrganisation}{contact.contact_type:label}{/capture}
{capture assign=addressee}{contact.addressee}{/capture}
{if $typeOrganisation eq 'Organisation'}
{capture assign=custom378}{contact.custom_378}{/capture}
{capture assign=custom379}{contact.custom_379}{/capture}
{if $custom378 neq ''}
{if $custom378}{$custom378}<br/>{/if}
{if $custom379}{$custom379}<br/>{/if}
{else}
{if $addressee neq ''}{$addressee}<br/>{/if}
{/if}
{else}
{capture assign=adresstype}{contact.location_type_id}{/capture}
{if $adresstype eq 1}
{if $addressee neq ''}{$addressee}<br/>{/if}
{else if $adresstype eq 2}
{capture assign=relatedcustom378a}{related.custom_378___reltype_a_Employee_of_Employer_of}{/capture}
{capture assign=relatedcustom379a}{related.custom_379___reltype_a_Employee_of_Employer_of}{/capture}
{if $relatedcustom378a neq ''}
{if $relatedcustom378a}{$relatedcustom378a}378a<br/>{/if}
{if $relatedcustom379a}{$relatedcustom379a}379a<br/>{/if}
{if $addressee}{$addressee}<br />{/if}
{/if}
{capture assign=relatedcustom378b}{related.custom_378___reltype_b_Employee_of_Employer_of}{/capture}
{capture assign=relatedcustom379b}{related.custom_379___reltype_b_Employee_of_Employer_of}{/capture}
{if $relatedcustom378b neq ''}
{if $relatedcustom378b}{$relatedcustom378b}378b<br/>{/if}
{if $relatedcustom379b}{$relatedcustom379b}379b<br/>{/if}
{if $addressee}{$addressee}<br />{/if}
{/if}
{if $relatedcustom378a eq ''}
{if $relatedcustom378b eq ''}
{capture assign=employerdisplayname}{contact.employer_id.display_name}{/capture}
{if $employerdisplayname}{$employerdisplayname}dpname<br />{/if}
{if $addressee}{$addressee}<br />{/if}
{/if}
{/if}
{/if}
{/if}
2
  • This plugin was the solution: civicrm.stackexchange.com/questions/45684/…
    – atcivicrm
    Feb 14 at 12:08
  • 1
    Welcome to SE! I was going to comment that this looks complex just to get a salutation, and you might find it easier using SearchKit Tokens - but I'm please to see you have found that already. You could create an answer explaining how you did it to help others facing something similar. (It's fine in SE to answer your own question.)
    – Aidan
    Feb 14 at 17:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.