Clickable Link Variable on Catalog Items

Michael H1
Tera Guru

Hi,

I have tried researching the best way to accomplish the following but so far have not had much success and am curious if anyone else has.

Scenario: I have an inbound action that reads in an email from another system and it kicks off a catalog item for internal users to process a request. One of the fields is currently a string field that is a link to a document in the other system. While the internal users can copy the link and paste it in another tab to open it, they have requested a clickable link for ease of use. Accomplishing this would also help in the future for similar items.

While this is a really good thread, I am not quite sure how I could use this widget to dynamically set the document link based on the link being processed in the inbound action: https://www.servicenow.com/community/now-platform-forum/how-to-include-a-clickable-link-on-the-catal...

Dynamically altering a Rich Text Label variable seemed like a good route to take but the Service Catalog Variable Types documentation specifically says that the g_form.setValue() API is not supported in Catalog Client Scripts, so I am unable to set this. It also does not appear it can be set using the Cart API in the inbound action: https://docs.servicenow.com/en-US/bundle/tokyo-servicenow-platform/page/product/service-catalog-mana...

 

Has anyone accomplished this before successfully with low maintenance? I did find some external sources outside of the community that used custom Jelly scripts but I was running into very odd UI issues in the client during implementation and others recommended against it for long term use.

As an aside, does anyone know why the URL Catalog Item variable type is not clickable the way the URL type field is on tables in ServiceNow? Not that it is relevant, but I have not found a reason why the clickable functionality offered for the URL field type on tables does not extend or is not mirrored to the Catalog Item URL variable type. The only functionality the URL Catalog Item variable type appears to offer is HTTP, HTTPS, FTP validation, which almost seems unnecessary considering how convenient ServiceNow makes it to implement Regex checks.

3 REPLIES 3

Sai Shravan
Mega Sage

Hi @Michael H1 ,

 

It sounds like you are trying to display a clickable link in a catalog item form. One way to accomplish this would be to use a UI policy to update the field in the form to a clickable link when the form loads. You can use a "Client Script" to achieve this. Inside the client script use

g_form.setDisplayValue(field name, '<a href=' + field value + '>' + field value + '</a>'); 

to set the display value of the field with a clickable link.

 

Another way to achieve this is to use a catalog client script to add a clickable link to the form. You can use the "addInfoMessage" method to add a clickable link to the form.

 

Regarding the URL Catalog Item variable type, it is not clickable because it is designed for validation of URLs rather than for displaying clickable links. The URL field type on tables is designed for displaying clickable links, which is why it is clickable.

 

In summary, you can use a UI policy and client script to achieve the desired functionality of displaying a clickable link in a catalog item form. However, it is not possible to use the g_form.setValue() method in catalog client scripts, so you need to use alternative methods such as g_form.setDisplayValue() or the addInfoMessage method to achieve the same result.

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Sai,

If I'm not wrong you can't use g_form.setDisplayValue in a client script. I tried to use your example to have my URL variable type clickable but it doesn't populate the field. With all the research I've done there is no way currently to make the URL type clickable. This did however work with the ErrorMessage, but I had to be more creative on the formatting. Since the client script can't use gs.getProperty I built a script include to get the instance name and set that to a hidden variable "instance_name" so I could use that for the client script. This allowed me to populate the link with the current instance name & other values. I left out the reset of my code but this will a starting point for a clickable ErrorMessage.

Client Onload Script for Instance:

function onLoad() {
var instance = new GlideAjax('getInstance');
instance.addParam('sysparm_name', 'getInstanceName');
instance.getXMLAnswer(instanceAnswer);

function instanceAnswer(response) {
var answer = response;
g_form.setValue('instance_name', answer);
}

}

===========

Script Include Instance Name return:

var getInstance = Class.create();
getInstance.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getInstanceName: function(){
var instanceName = gs.getProperty('instance_name');
return(instanceName);
},
type: 'getInstance'
});

==================

Client Script onChange:

var server = g_form.getValue('Your variable');
var myInstance = g_form.getValue('instance_name'); // Gets the instance I'm logged into from above AJAX call

var targetTable1 = 'cmdb_rel_ci';
var query1 = 'parent.sys_idIN' + server;  //I dot walked since I'm using a Glide List with sysIDs
var url1 = 'https://'+ myInstance + '.service-now.com/' + targetTable1 + '_list.do?sysparm_query=' + query1;
var urlString1 = '<p><a class="web" target="_blank" href="' + url1 + '">' + "Click Here" + '</a></p>'; //Use _blank so it will open a new window

var msg1 = ('Description you want' + urlString1);


g_form.addErrorMessage(msg1);

=============

-O-
Kilo Patron
Kilo Patron

I would go for Macro + Widget.

Also because I don't think there is no other decent option.

Still better than DOM manipulate the ... out of it.

I would expect it to be low maintenance too - I don't see SN doing much changes to Portal or CMS so that a solution crafted now would need re-crafting in the near future.

The only problem I can see with this approach is if this field needs to be mandatory.

OOB mandatory functionality cannot be implemented (in an elegant way) in Portal (maybe CMS neither).