Dynamic URL Field Naming in Cross-Module Related Field Display

Author: Yuri Gee

Date: 19 May 2025

7 minute read time

In this discussion, I will introduce a method for assigning an intuitive and user-friendly URL field name that can also be dynamically set. This approach will be demonstrated using an example of displaying a clickable related field across multiple modules, such as linking the assigned Account Manager to a case record.

Scenario

You can currently use the Record View Dashlet in the Case focus drawer to quickly display the Account Manager associated with the case’s related account. However, by implementing a simple extension to the default URL view, the URL field can be leveraged to display this same information directly within the record view or list view.

Additionally, this extension enables the URL field to have an intuitive and readable name, rather than a standard URL link, making it adaptable for any scenario requiring a URL field.

Here’s how it will appear before and after the implementation: the URL link will be replaced with the User name (Account Manager), which can differ from the Case Owner.

Before implementation URL is displayed as a link

After implementation the URL displays Account manager name 

Here’s how it will appear in the Cases list view.

URL field in the List View

Implementing URL naming

URL record and list views, like many other SugarCRM field views, are built on Handlebar templates. By making simple extensions to the following files using stock Handlebar helpers (functions), you can effectively implement both a static and a dynamic URL name. This is achieved by referencing another text field within the same module where the URL field exists containing the URL name and ensuring it is added or made available in the layout. The reference is established by utilizing the Comments section of the URL field (in Studio) to specify the name field. If dynamic name generation is required, a calculated formula can then be applied to the name field itself.

custom/clients/base/fields/url/detail.hbs

Fullscreen
1
2
3
4
5
6
7
8
9
{{#if value}}
<span class="ellipsis_inline" data-bs-placement="bottom" title="{{value}}">
{{#if def.isClickable}}
<a {{#if def.link_target}}target="{{def.link_target}}"{{/if}} href="{{value}}"{{#if dir}} dir="{{dir}}"{{/if}}>{{#match def.comments "^urlname"}} {{fieldValue this.model def.comments}} {{else}} {{value}} {{/match}}</a>
{{else}}
{{value}}
{{/if}}
</span>
{{/if}}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

custom/clients/base/fields/url/list.hbs

Fullscreen
1
2
3
4
5
6
7
{{#if value}}
{{#if def.isClickable}}
<a class="ellipsis_inline" data-bs-placement="bottom" title="{{value}}" {{#if def.link_target}}target="{{def.link_target}}"{{/if}} href="{{value}}">{{#match def.comments "^urlname"}} {{fieldValue this.model def.comments}} {{else}} {{value}} {{/match}}</a>
{{else}}
<span class="ellipsis_inline" data-bs-placement="bottom" title="{{value}}">{{value}}</span>
{{/if}}
{{/if}}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

This approach maintains compatibility with the existing code when the Comments section of a URL field is either left empty or does not begin with the designated regular expression pattern 'urlname'.

Implementing Sugar Formulas to resolve the related field

Now that the Handlebars templates for the URL fields have been updated, we can implement the logic to display the Account Manager for the Case record.

To achieve this, create the following calculated text fields in Studio – Accounts module:

accountmgr_id_c with the formula: related($assigned_user_link,"id")

accountmgr_name_c with the formula: concat(related($assigned_user_link,"first_name")," ",related($assigned_user_link,"last_name"))

Both fields could be combined, but doing so would require a more complex formula to extract the data in the Cases module.

Studio calculated fields in Accounts and Cases modules

Next, in the Cases module, create a text field accountmgr_id_c with the formula: related($accounts,"accountmgr_id_c")

Field representing Account Id in Cases module

and the URL field accountmgr_url_c with the following parameters:

Comments: urlname_accountmgr_url_c

Generate URL: accountmgr_id_c

Default Value: https://<your SugarCRM URL>/#Users/{accountmgr_id_c}

Here, the accountmgr_id_c field is used to generate an ID within the link, while the urlname_accountmgr_url_c provides the display name field for the URL.

Clickable URL field representing Account Manager

Finally, create a text field urlname_accountmgr_url_c in the Cases module with the formula: related($accounts,"accountmgr_name_c") with Visible If set to false to ensure the field is hidden from the layout view for users

Field representing the user-friendly name for the URL field

Add both the URL field and its corresponding name field to the Record, List, and RecordView layouts via Studio.

This will ensure the Account Manager name and correct URL link are dynamically resolved and displayed as part of the URL field every time it changes on the Account and account record is re-saved if automatic recalculation of related fields is enabled.

Additional notes

The Handlebars template examples provided here were tested in SugarCRM 25.1. However, before considering them for production deployment, please make sure to run Quick Repair and Rebuild to apply and test the templates in a test instance.

Additionally, fields max sizes can be adjusted to optimize space usage—for instance, Account ID fields should ideally be limited to 36 characters.

I’d love to hear your thoughts and feedback on this discussion, including the related scenarios and proposed implementations!