
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 03:15 PM
I have a business rule that when a sc_task is created, all the catalog item variable labels and values are copied in text format into the description field of the sc_task - works well.
The issue I'm having is that it is copying all variables, I want it to not include the hidden variables, so anyone who is able to assist I'd be grateful.
(function executeRule(current, previous /*null when async*/ ) {
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.request_item);
set.load();
var vs = set.getFlatQuestions();
var description = '';
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '' && vs.get(i).getDisplayValue() != 'false') {
description = description + vs.get(i).getLabel() + " : " + vs.get(i).getDisplayValue() + "\n";
}
}
current.description = description;
})
(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 08:18 PM - edited 11-26-2024 08:19 PM
Hi @Bidduam
Try with the below script. We need to glide into Item Option table and filter out hidden fields for your requirement.
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.request_item);
set.load();
var vs = set.getFlatQuestions();
var description = '';
for (var i = 0; i < vs.size(); i++) {
var grOption = new GlideRecord("item_option_new");
grOption.get(vs.get(i).getId());
if (grOption.hidden == false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '' && vs.get(i).getDisplayValue() != 'false') {
description = description + vs.get(i).getLabel() + " : " + vs.get(i).getDisplayValue() + "\n";
gs.info(description);
}
}
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 03:38 PM
Then you would need to glide into Item Option table and filter out hidden fields.
Please mark it as helpful if this helped.
Salma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 08:18 PM - edited 11-26-2024 08:19 PM
Hi @Bidduam
Try with the below script. We need to glide into Item Option table and filter out hidden fields for your requirement.
var keys = new Array();
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.request_item);
set.load();
var vs = set.getFlatQuestions();
var description = '';
for (var i = 0; i < vs.size(); i++) {
var grOption = new GlideRecord("item_option_new");
grOption.get(vs.get(i).getId());
if (grOption.hidden == false && vs.get(i).getLabel() != '' && vs.get(i).getDisplayValue() != '' && vs.get(i).getDisplayValue() != 'false') {
description = description + vs.get(i).getLabel() + " : " + vs.get(i).getDisplayValue() + "\n";
gs.info(description);
}
}
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 09:44 PM
Works great thank you @Amit Verma 😁
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2024 08:23 PM
@Bidduam To exclude hidden variables from being copied to the description field in your business rule, you can use the isVisible() method from the variable object. This method checks if the variable is set to be visible on the form.