How do I get to a Variable record to pull the value of a field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 11:13 AM
I have a mail script that is used to display Variable questions and answers (see below). I haven't been able to determine a way to get to a field on the Variables table so I can include it in my condition, the end goal being an easier way to flag Variables we don't want to be shown in email
This doesn't help, because there's no documentation on .getQuestion() beyond it: https://docs.servicenow.com/en-US/bundle/utah-application-development/page/script/server-scripting/c...
The only other post I found was from over 5 yrs ago, and the solution doesn't work: https://www.servicenow.com/community/now-platform-forum/how-do-i-get-the-value-of-a-field-on-the-que...
if (current.sys_class_name == 'sc_req_item' || current.sys_class_name == 'sc_task' || current.sysapproval.getRefRecord().getTableName() == 'sc_req_item') { //Start all Variables
template.print('<p><strong>Request Details</strong></p>');
if (current.sys_class_name == 'sc_req_item' || current.sys_class_name == 'sc_task') { //Requested Items only
var rec = current.sys_id;
var recV = current.variables;
var variables = current.variables.getElements();
}
if (current.sysapproval.getRefRecord().getTableName() == 'sc_req_item' || current.sysapproval.getRefRecord().getTableName() == 'sc_task') { //Approvals for Requested items only
rec = current.sysapproval.sys_id;
recV = current.sysapproval.variables;
variables = current.sysapproval.variables.getElements();
}
//Create the Variables table
template.print('<div><p><table><tr>');
template.print('<td>Question</td>');
template.print('<td>Answer</td>');
template.print('</tr>');
for (var i = 0; i < variables.length; i++) {
var question = variables[i].getQuestion();
if (question.getLabel() != '' && question.getDisplayValue() != '' && question.getDisplayValue() != 'false' && question.getDisplayValue() != '-- Not Defined --'){
template.print('<tr><td>' + question.getLabel() + '</td><td>' + question.getDisplayValue() + '</td></tr>');
}
}