Show Variable Set Titles in Email Notifications

rba-chris
Kilo Expert

Hi Everyone,

I've got some variable sets used in Service Catalog items that have a title on them. For example, a variable set for requesting a computer. The variable set has a title of "Computer Hardware".

How can I access that in a mail script to show in a notification? I guessed (incorrectly) to use getTitle(). Is this possible?

Thanks!

Chris Schuh

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Unfortunately there isn't an API to get the variable set container details.  When a catalog item is ordered, the code loops through all the associated item variables and creates "instances" of each one linked to the task.  Details on knowing it was originally part of a variable set are unknown at that level.

In the out of the box mail script code you will see functions like getLabel() and getDisplayValue(), there is also getId() which is the SysID of the variable that is linked to the catalog item/variable set.  You could use this SysID and do a lookup to get the Variable Set name.  This could be "expensive" in your notifications emails though depending on how many variables you have as it will be performing the query over and over again.

var variableRec = new GlideRecord("item_option_new");
variableRec.get(vs.get(i).getId());
template.print(variableRec.cat_item.getDisplayValue());

or


template.print(variableRec.variable_set.getDisplayValue());

View solution in original post

2 REPLIES 2

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Unfortunately there isn't an API to get the variable set container details.  When a catalog item is ordered, the code loops through all the associated item variables and creates "instances" of each one linked to the task.  Details on knowing it was originally part of a variable set are unknown at that level.

In the out of the box mail script code you will see functions like getLabel() and getDisplayValue(), there is also getId() which is the SysID of the variable that is linked to the catalog item/variable set.  You could use this SysID and do a lookup to get the Variable Set name.  This could be "expensive" in your notifications emails though depending on how many variables you have as it will be performing the query over and over again.

var variableRec = new GlideRecord("item_option_new");
variableRec.get(vs.get(i).getId());
template.print(variableRec.cat_item.getDisplayValue());

or


template.print(variableRec.variable_set.getDisplayValue());

rba-chris
Kilo Expert

Thank you so much - it is greatly appreciated. I'll have to weigh the cost of running it and see if it has a huge impact on performance, as we do intend use it in a loop.