How to pull only active fields using GlideappVariablePoolQuestionSet in email script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 06:24 AM
Hi
I would like to pull only active fields in email notification. There is one email notification script to pull all the variables associated to the RITM but it is pulling inactive fields as well
Below is the email script which is responsible to pull the variables associated to the RITM (notification written on sysapproval table)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2025 06:28 AM
it won't work directly.
you will have to enhance and query to know if it's active or not
something like this
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.getValue('sysapproval'));
set.load();
var vs = set.getFlatQuestions();
// Step 1: Collect all variable sys_ids from the questions
var varSysIds = [];
for (var i = 0; i < vs.size(); i++) {
varSysIds.push(vs.get(i).getID());
}
// Step 2: Query all active variables in one go
var activeVars = {};
var grVar = new GlideRecord('item_option_new');
grVar.addQuery('sys_id', 'IN', varSysIds.join(','));
grVar.addQuery('active', true);
grVar.query();
while (grVar.next()) {
activeVars[grVar.getValue('sys_id')] = true;
}
// Step 3: Only print variables that are active
for (var j = 0; j < vs.size(); j++) {
var question = vs.get(j);
var varSysId = question.getID();
if (activeVars[varSysId]) {
if (question.getLabel() != '' && question.getDisplayValue() != '' && question.getDisplayValue() != 'false') {
template.space(4);
template.print(question.getLabel() + " : " + "<br>" + " " + question.getDisplayValue() + "<br><br/>");
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2025 08:54 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader