- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2018 12:20 AM
Hi all,
I have a record producer that I want to copy some variables over to the work notes.
I found the thread below which shows how and have it working with plain text, however, I am having issues with reference fields.
When I add a reference field as a variable, the script does not run and I don't even get the Variables: in the work notes. Here is the script:
var wn = 'Variables:';
for (var key in producer)
if (producer[key]) {
if (key.search('boom') != -1) {
var v = producer[key];
wn += '\n' + v.getGlideObject().getQuestion().getLabel() + ': ' + v.getDisplayValue();
}
}
current.work_notes = wn;
Any ideas?
Thanks, Brendan
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2018 09:20 PM
Ok. I thought you were using the question Label. Lets try this
(function executeRule(current, previous /*null when async*/) {
var desc = '';
var qtype = 0;
var q = new GlideRecord('question_answer');
q.addQuery('table_sys_id',current.sys_id);
q.orderBy('order');
q.query();
while (q.next())
{
if (q.value!='' && q.question.name.indexOf('boom')>-1 && q.value!='false' || q.question.type==11)
{
if (q.question.type==11)
desc = desc+'\n';
if (q.question.type!=7)
{
if (desc=='')
desc = q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
else
desc = desc+'\n'+q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
}
else
{
if (qtype==7)
desc = desc+','+q.question.getDisplayValue();
else
desc = desc+' '+q.question.getDisplayValue();
}
qtype = q.question.type;
}
if (q.question.type==19)
desc = desc+'\n';
}
if (desc!='')
current.description = desc;
})(current, previous);
function getRefValue(type,table,value)
{
if (type==8)
{
var ref = new GlideRecord(table);
ref.get(value);
return ref.getDisplayValue();
}
else
{
return value;
}
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2018 05:51 PM
You can try below code
(function executeRule(current, previous /*null when async*/) {
var desc = '';
var qtype = 0;
var q = new GlideRecord('question_answer');
q.addQuery('table_sys_id',current.sys_id);
q.orderBy('order');
q.query();
while (q.next())
{
if (q.value!='' && q.value.indexOf('boom')>-1 && q.value!='false' || q.question.type==11)
{
if (q.question.type==11)
desc = desc+'\n';
if (q.question.type!=7)
{
if (desc=='')
desc = q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
else
desc = desc+'\n'+q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
}
else
{
if (qtype==7)
desc = desc+','+q.question.getDisplayValue();
else
desc = desc+' '+q.question.getDisplayValue();
}
qtype = q.question.type;
}
if (q.question.type==19)
desc = desc+'\n';
}
if (desc!='')
current.description = desc;
})(current, previous);
function getRefValue(type,table,value)
{
if (type==8)
{
var ref = new GlideRecord(table);
ref.get(value);
return ref.getDisplayValue();
}
else
{
return value;
}
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2018 10:47 AM
Did it work for you? Can you mark it answered if it did and close the thread
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2018 04:39 PM
Hi Sanjiv,
I missed your notification the other day, so didn't know that you had written back, sorry!
I tried it, however, no variables were posted to the description.
I have verified that the variables are called 'boom_test_1' and 'boom_test_2'.
From the other script, they use the following:
if (key.search('boom') != -1)
I just wonder if q.value.indexOf('boom') is looking for a variable called boom and not one that contains the word boom?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2018 08:54 PM
Corrected my script
(function executeRule(current, previous /*null when async*/) {
var desc = '';
var qtype = 0;
var q = new GlideRecord('question_answer');
q.addQuery('table_sys_id',current.sys_id);
q.orderBy('order');
q.query();
while (q.next())
{
if (q.value!='' && q.question.question_text.indexOf('boom')>-1 && q.value!='false' || q.question.type==11)
{
if (q.question.type==11)
desc = desc+'\n';
if (q.question.type!=7)
{
if (desc=='')
desc = q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
else
desc = desc+'\n'+q.question.getDisplayValue()+': '+getRefValue(q.question.type,q.question.reference,q.value);
}
else
{
if (qtype==7)
desc = desc+','+q.question.getDisplayValue();
else
desc = desc+' '+q.question.getDisplayValue();
}
qtype = q.question.type;
}
if (q.question.type==19)
desc = desc+'\n';
}
if (desc!='')
current.description = desc;
})(current, previous);
function getRefValue(type,table,value)
{
if (type==8)
{
var ref = new GlideRecord(table);
ref.get(value);
return ref.getDisplayValue();
}
else
{
return value;
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2018 09:14 PM
Hey mate, thanks for getting back to me.
I have tried the amended script, however, still, nothing gets posted into the description.