Pass Record Producer variables questions and answers to Description field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 07:52 AM
Hi,
I have created a Record Producer form for our incident table. They don't want the variable editor on the Incident form, so instead to retrieve the questions and answers I suggested we pass them into the description field.
I found this script and it sort of works.
var populatedList = '';
for (v in current.variables) {
var question = current.variables[v].getQuestion();
if(question.getLabel() != '');
{
populatedList += question.getLabel() + ":" + question.getDisplayValue() + '\n';
}
}
But it is retrieving all the variables questions and answers, including those that are not answered and null fields.
Does anyone have a better script for this?
Any help would be appreciated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 08:29 AM
You can use record producer script like below to pass particular variables to incident description.
current.description = producer.comments + producer.name; // comments and name are the name of record producer variables
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 11:43 AM
Hi
I am not trying to pass values individual. I want to pull all the questions and answers that were filled out. Kind of like I want to pull the variable summary, which will only show me the questions that were filled out.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 11:50 AM
Record producer variable values are stored in question_answer table.
Your record producer script can query question_answer to get questions and answers.
You can use sample script like below to get all RP variable values.
var jsonObj = {};
var arr = [];
var obj = {};
var incRec = new GlideRecord('question_answer');
incRec.addQuery('table_sys_id', '7d28cea5dbf00010b94b58b3ca9619b9');
incRec.query();
while (incRec.next()) {
var variableValue = incRec.value;
var variableLabel = incRec.question.getDisplayValue();
//check to see if 'value' is the sys_id
if (variableValue.toString().length == 32) {
var ciGR = new GlideRecord('cmdb_ci');
ciGR.get(variableValue);
ciGR.query();
if (ciGR.next()) {
//now you can retrieve any value related to sys_id
variableValue = ciGR.name;
}
}
gs.print('Question is: ' + variableLabel + ' || Value is: ' + variableValue);
obj[variableLabel] = variableValue.toString();
}
arr.push(obj);
jsonObj.Variables = arr;
gs.info(JSON.stringify(jsonObj));
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2022 02:55 PM
Hi
This script works, but with the some of my values are reference fields and are display at the sys_id.
Am I able to retrieve the display name or am I going to have to query the table to retrieve the display name of that sys_id?