Changing the question/label of variables in variable sets per catalog item

lars7
Tera Guru

Hi

 

I am working on enhancing the end-user experience on a client's Service Portal. Specifically, the client want more annotations/tool tips, in a standardized way, in order to better guide the users on what to select or type in when making a request. What we talked about, then, was to consolidate similar variables across catalog items into variable sets so that we can control the annotations/tool tips from one place, as well as reference qualifiers and attributes etc. which we put in everytime. One example could be a List Collecter variable on the sys_user table with certain reference qualifers and attributes which we use in many catalog items.

 

However, depending on the specific catalog item in question, the variable's question/label may often need to be worded differently for contextual purposes. And I guess we would then have to use catalog client scripts to change the wording. But that would kind of defeat the purpose of this exercise because it would just shift the complexity from having many similar variables to having many similar catalog client scripts. My question is if anybody else has had this kind of requirement and found a good solution to it?

 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@lars7 

I don't think there is another option other than creating catalog client script on every catalog item to change the variable label as per catalog item.

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

Chandresh Tiwa1
Tera Contributor

Hi, never came across such requirement but one possible solution would be that add a catalog client script in the variable set for all such variables. And provide name dynamically using system properties.

For example, Let's assume there is a reference variable with name "user" for one catalog item (sysid - AAA) called "Caller" and for another catalog item (sysid - BBB) called  "Requester" .

So, in this case create two system properties - "user_AAA" & "user_BBB". Add the values as your required labels. Now add catalog client script in variable set and in the code add -

 

var cat_item = $sp.getParameter("sys_id");
g_form.setLabelOf('user', gs.getProperty('user_'+cat_item)) ;

 

 This way add all the required variables once in the client script and in future whenever you create a new catalog item using variable set add new system property. This saves you from creating multiple client scripts.

 

Please mark solved, if you think this solution was helpful.

 

Regards,

Chandresh

Thanks for the reply

 

I am getting this error when trying your solution: 

"The object "gs" should not be used in client scripts."

 

 

Hey sorry, since this is client script ofc "gs" can't be used and therefore sys_properties can't be used. Instead you can use "sys_ui_message" table. Create a message just like you created property before.

I created a variable set in my pdi and added two variables 'user' and 'phone'.

ChandreshTiwa1_0-1681996150713.png

 

Added the variable set to two catalog items. Then added four messages in the message table like below.

ChandreshTiwa1_1-1681996192734.png

 

then added client script in the variable set

function onLoad() {
var cat_item = g_form.getUniqueValue();
//add the variables below in getMessage
getMessage('user_'+cat_item,function(msg){callback(msg,'user')});
getMessage('phone_'+cat_item,function(msg){callback(msg,'phone')});
}
function callback(msg,variable) //to prevent it for items where label should be default
{
	if(!msg.startsWith(variable+'_'))
	{
	g_form.setLabelOf(variable,msg);
	}
}

Works as expected for me.

 

Regards,

Chandresh