- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
I'm using the script below to include the catalogue variables in the Word document after submitting the request. However, the issue is that the Word file is getting updated with the sys IDs of the variable values. The variable types are Single line text and Select box
Script Include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
don't use sc_item_option_mtom table.
Instead use this logic for getting variables
_getVariables: function(ritmSysId) {
var vars = [];
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
var variableLabel = vs.get(i).getLabel();
var variableValue = vs.get(i).getDisplayValue();
vars.push({
name: variableLabel,
value: variableValue
});
}
return vars;
},
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi @GBS
You’re pulling from sc_item_option_mtom → sc_item_option.value, which always stores the raw value. For reference and select box variables you must resolve the display text yourself.
In your _getVariables() replace the value line with logic that:
- If the variable is reference / lookup select box / list collector → fetch the record from the reference table and use its display value.
- If the variable is a select box (non-reference) → look up the label in question_choice for that question/value.
- Else → use the raw text for Single line texts.
Here’s a "rough" (non-tested) replacement for _getVariables:
_getVariables: function(ritmSysId) {
var out = [];
var mtom = new GlideRecord('sc_item_option_mtom');
mtom.addQuery('request_item', ritmSysId);
mtom.query();
while (mtom.next()) {
var q = mtom.sc_item_option.item_option_new; // variable definition (item_option_new)
var name = q.getDisplayValue('question_text') || q.getDisplayValue('name');
var raw = mtom.sc_item_option.value + '';
var disp = raw;
var typeName = q.getDisplayValue('type'); // e.g., "Reference", "Select Box", "List Collector"
var refTable = q.getValue('reference'); // set for reference types
// Reference / Lookup Select Box / List Collector → resolve display from ref table
if (refTable) {
var ref = new GlideRecord(refTable);
if (ref.get(raw)) disp = ref.getDisplayValue();
}
// Plain Select Box (choices defined on the variable) → resolve label from question_choice
else if (typeName === 'Select Box') {
var ch = new GlideRecord('question_choice');
ch.addQuery('question', q.getUniqueValue());
ch.addQuery('value', raw);
ch.query();
if (ch.next()) disp = ch.getValue('text') || ch.getValue('label') || raw;
}
// else: Single Line Text / etc. → raw is already the display
out.push({ name: name, value: disp });
}
return out;
}
getDisplayValue('value') on sc_item_option won’t translate sys_ids for reference/select variables. it’s just a string field. Resolving via the reference table or question_choice gives you the human-readable label you expect.
If you still see sys_ids:
Confirm the variable’s type (q.getDisplayValue('type')) and reference table (q.reference) are set as expected.
For list collectors, raw is a comma-separated list of sys_ids; split and map each to its display value using the same reference-table lookup loop.
Please mark as correct and helpful if it solved your query.
Harish
✔️ Kindly mark as Helpful / Accept Solution if this answered your question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi @GBS ,
In your _getVariables method, you're retrieving variable values using:
var variableValue = variables.sc_item_option.getDisplayValue("value") || variables.sc_item_option.value;
Since you're dot-walking through multiple records, getDisplayValue in this case returns the display value of the sc_item_option record itself, which is typically the sys_id for this table.
To correctly retrieve the display value of the actual variable, you need to explicitly access the 'value' field and then call getDisplayValue() on it, like this:
var variableValue =
variables.sc_item_option.value.getDisplayValue() ||
variables.sc_item_option.value;
So, only 1 line change will resolve ✔️ your issue!
If this solution helps you then, mark it as accepted solution ✔️ and give thumbs up 👍!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
don't use sc_item_option_mtom table.
Instead use this logic for getting variables
_getVariables: function(ritmSysId) {
var vars = [];
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritmSysId);
set.load();
var vs = set.getFlatQuestions();
for (var i = 0; i < vs.size(); i++) {
var variableLabel = vs.get(i).getLabel();
var variableValue = vs.get(i).getDisplayValue();
vars.push({
name: variableLabel,
value: variableValue
});
}
return vars;
},
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
