Dynamic URL on field Label

NFGDom
Mega Sage

Hello!

I'm looking for some guidance on how to set this up. I want to have a URL on a label that pulls in the value of its field to point to a location. The URL prefix would be "https://<instance>.atlassian.net/browse/" and the suffix would be value of the field; example "SNOW-1234".

Let me know if I can provide any other information & thanks in advance!

Dom

14 REPLIES 14

Hi,

you can just give link and not the label

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I can, I was just thinking it would look better to use it as hyper-text.

for example:

https://servicenow.com

vs

ServiceNow

the second is preferred.

DominikBenner
Tera Contributor

You found a solution for this?

I haven't - but if anyone has found something I'm all ears.

@NFGDom & @DominikBenner 

You should be able to use an HTML field to display the clickable link with your preferred label.

First I would try creating an HTML field and have the value set to be the properly formatted link but I have experienced issues in certain instances with this approach in the past. So generally what I find to work more consistently is to have a blank HTML field that you configure where you want it on the form. Then use an onLoad client script to set the value of the HTML field.

Here is an example of what the client script might look like to populate a blank html field:

 

function onLoad() {
     var urlField = g_form.getValue('jira_url') //replace jira_url with the actual field name in your table.

     if (!urlField || urlField.trim() === '') {
          g_form.setValue('url_html', 'No Jira Link Available'); //replace url_html with the html field name.
          return;
     }

     var urlLabel = 'Your_Label'; //Set the text you want displayed as the link here.
     var htmlContent = ''; //I prefer to set this in the following format for code organization and redability but can just make it a giant string if you want.

     htmlContent += '' +
          '<div class="JiraURL">' +
          '<a href="' + urlField + '">' + urlLabel + '</a>'
          '</div>';

     g_form.setValue('url_html', htmlContent);
}

careful in the code view as it doesn't do a good job of showing the difference between '' (' ' with no space) and ".


Using this approach the HTML field should render the HTML on the form where the field value would normally be displayed. You can use either the div tag or the hyperlink tag to apply any additional formatting.