The CreatorCon Call for Content is officially open! Get started here.

SUBHAM_SHAW_SN
Tera Guru
Tera Guru

Use case : There are instances where the customer might ask you to place a URL on the Service Catalog form so that the end user can navigate to a certain page by hitting the same. In this case , "CUSTOM WITH LABEL" (earlier knows as Macro With Label) variable type can be used to build fancy URLs.

Solution:  Consider a scenario where we would like to place a URL link on the catalog form which will take us to Create Incident form in ServiceNow . This will be a dynamic url adjusting based on the environment(DEV,QA,PROD etc.) that we are into.

 

Step 1 : Create a widget named "Generate URL" with the following code :

Server Script :

(function() {

	var baseURL=gs.getProperty('glide.servlet.uri');        //Returns the base URL
	data.url=baseURL+options.extended_url;

})();

 

The options schema in the above code on the server contains the following component :

Subham11_1-1676574157089.png

 

 

 

HTML Template :

<div> 
  <a href='{{data.url}}'>Click here to raise an incident</a>
</div>

 

CSS :

a:link, a:visited {
  background-color: #f44336;
  color: white;
  padding: 14px 25px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}

a:hover, a:active {
  background-color: red;
}

 

Subham11_0-1676574050423.png

 

Step 2 : Once the widget is created , create a catalog variable of type "Custom with Label". Go to the Type Specifications of the variable and tag the widget as shown below :

Subham11_2-1676574352436.png

 

 

Boom !! your styled/fancy URL is ready to be viewed on the portal. This is how it looks in my case :

Subham11_3-1676574508601.png

 

 

Thanks & Regards,

Subham Kumar Shaw

Senior ServiceNow Consultant
ServiceNow Community Rising Star '2022/2023

 

Comments
Ishaan Shoor
Mega Sage
Mega Sage

Thanks for sharing! 

Uncle Rob
Kilo Patron

This is awesome.

MohjaB
Tera Contributor

Thanks @SUBHAM_SHAW_SN , this is very helpful!

Any ideas how can I inject information from field creation to the HTML code? For example, I created a widget and  the question prompt is in the HTML section, which is different for each variable.

GB14
Kilo Patron

@SUBHAM_SHAW_SN  How can we show this widget on the ITIL view using Macro?

Version history
Last update:
‎02-16-2023 11:12 AM
Updated by:
Contributors