requirement is when a user wants to add the name of a primary contact to an email template, the below code can be used.
Solution
Navigate to Customization > Lists, Records, & Fields > Entity Fields > New
Label: Enter a name (Example: Primary Contact)
Type: Select Free-Form Text
Store Value: Remove Checkmark
Click Applies To
Customer: Remove Checkmark
Click Display
Subtab: Select Main
Click Validation & Defaulting
Formula: Enter Checkmark
Default Value: Enter {contactprimary.entityid}
Click Save or Save & Apply to Forms
Note: After saving, take note of the custom field's ID (i.e. custentityXX).
Navigate to Documents > Templates > Email Templates > New
Name: Enter a name
Text Editor: Enter ${customer.custentityXX}