How can I selectively display variables on the Service Portal Ticket Form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2016 11:09 AM
The Service Portal Ticket Form Options toggle seems to show every variable used on that Catalog Item. How can I choose which ones are displayed? I have created a new true/false field on the item_option_new table that I can use to distinguish what should be visible, but can't connect the dots to incorporate this new field to qualify the API call in my cloned Widget.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2017 06:15 PM
The default script does a loop on data.variables, which is retrieved via:
data.variables = $sp.getVariablesArray();
Now I don't know whether the getVariablesArray function gets all of the fields for the variables, but if it does then you could simply use ng-if to only display what you want:
<div class="m-b break-word" ng-repeat="variable in data.variables">
<div ng-if="variable.item_option_new">
<label class="m-n">{{variable.label}}</label>
<div>{{variable.display_value}}</div>
</div>
</div>
Alternatively you could use ArrayUtil to remove the desired fields from the array via indexOf and splice, though I haven't tried this before. Something like this:
How to splice an array out of a nested array - javascript - Stack Overflow
You could take a look at the structure of the array using:
console.table(data.variables);
Which will print out the whole array to your browser console.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2017 10:12 PM
I used the code below to hide 'false' variables:
<div ng-if="variable.display_value != 'false'">
<label class="m-n">{{variable.label}}</label>
<div>{{variable.display_value}}</div>
</div>
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2017 06:18 PM
Hi All,
Would you know where does service now get the value
$sp.getVariablesArray();
I am using ticket form for multiple tables and some how it is not displaying anything for sc_req_item table while it is displaying properly from incident table and project table.
Thanks
Broderick

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2017 11:59 AM
Hi Brad,
One of the attributes of the object returned in the data.variables array is "visible_summary", which ties back to the Visible summary checkbox on the variable form. You can make a copy of the 'TIcket Fields' widget and use this to control the visibility of a variable in this widget.
Lines 38-41
<div class="m-b break-word" ng-repeat="variable in data.variables">
<label ng-if="variable.visible_summary" class="m-n">{{variable.label}}</label>
<div ng-if="variable.visible_summary">{{variable.display_value}}</div>
</div>
If you are interested in viewing all of the attributes of the variable object you can add the following script at the end of your Server Script. This should only be used for testing as it does add multiple log statements for each variable.
for (var i = 0; i < data.variables.length; i++) {
for (var key in data.variables[i]) {
gs.log("Portal Item Variable " + i + " | " + key + ": " + data.variables[i][key].toString());
}
}