Body: <p>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.</p>
  <p>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.</p>
  <p>Here's the unique aspect: The related tokens plugin (<a href="https://github.com/twomice/com.joineryhq.reltoken" rel="nofollow noreferrer">https://github.com/twomice/com.joineryhq.reltoken</a>) 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.</p>
  <p>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.</p>
  <p>Thank you.</p>
  <p>Here the Code:</p>
  <pre><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}&lt;br/&gt;{/if}
  {if $custom379}{$custom379}&lt;br/&gt;{/if}
  {else}
  {if $addressee neq ''}{$addressee}&lt;br/&gt;{/if}
  {/if}
  {else}
  {capture assign=adresstype}{contact.location_type_id}{/capture}
  {if $adresstype eq 1}
  {if $addressee neq ''}{$addressee}&lt;br/&gt;{/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&lt;br/&gt;{/if}
  {if $relatedcustom379a}{$relatedcustom379a}379a&lt;br/&gt;{/if}
  {if $addressee}{$addressee}&lt;br /&gt;{/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&lt;br/&gt;{/if}
  {if $relatedcustom379b}{$relatedcustom379b}379b&lt;br/&gt;{/if}
  {if $addressee}{$addressee}&lt;br /&gt;{/if}
  {/if}
  {if $relatedcustom378a eq ''}
  {if $relatedcustom378b eq ''}
  {capture assign=employerdisplayname}{contact.employer_id.display_name}{/capture}
  {if $employerdisplayname}{$employerdisplayname}dpname&lt;br /&gt;{/if}
  {if $addressee}{$addressee}&lt;br /&gt;{/if}
  {/if}
  {/if}
  {/if}
  {/if}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-14T12:08:25.963Z
Comments.Text: This plugin was the solution:
  https://civicrm.stackexchange.com/questions/45684/find-or-create-token-for-field-on-related-contact/45690#45690
Comments.UserDisplayName: atcivicrm
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-14T17:47:51.693Z
Comments.Text: 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.)
Comments.UserDisplayName: Aidan
Tags: <error><relationships><tokens><smarty>
Title: Assignment of related custom field occurs critical Error
ThreadText: # Assignment of related custom field occurs critical Error
  
  (Asked by: username_0 on 2024-02-14)
  
  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}{/if}
  {if $custom379}{$custom379}{/if}
  {else}
  {if $addressee neq ''}{$addressee}{/if}
  {/if}
  {else}
  {capture assign=adresstype}{contact.location_type_id}{/capture}
  {if $adresstype eq 1}
  {if $addressee neq ''}{$addressee}{/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{/if}
  {if $relatedcustom379a}{$relatedcustom379a}379a{/if}
  {if $addressee}{$addressee}{/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{/if}
  {if $relatedcustom379b}{$relatedcustom379b}379b{/if}
  {if $addressee}{$addressee}{/if}
  {/if}
  {if $relatedcustom378a eq ''}
  {if $relatedcustom378b eq ''}
  {capture assign=employerdisplayname}{contact.employer_id.display_name}{/capture}
  {if $employerdisplayname}{$employerdisplayname}dpname{/if}
  {if $addressee}{$addressee}{/if}
  {/if}
  {/if}
  {/if}
  {/if}
  
  **Tags:** error, relationships, tokens, smarty
  
  > **Comments:**
  > **username_0**: This plugin was the solution: https://civicrm.stackexchange.com/questions/45684/find-or-create-token-for-field-on-related-contact/45690#45690  
  > **username_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.)  
  
  ---
  
  ## 0 answers
  
  