- 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 12:32 AM
Hi Brendan,
Why not copy them using simple statement as below
current.work_notes = producer.<variable1> + " " + producer.<variable2>;
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2018 12:51 AM
Hi Brendan,
There is simple way to achieve this.
Try to use any of the below code to get variables in work note.
current.work_notes = current.variables.<variable_name>;
Or
current.work_notes = procedure.<variable_name>;
Hit Correct if this helpful if you find my response worthy based on the impact.
Thanks
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2018 04:21 AM
cheers for replying guys.
I have looked into doing it the way that Ankur has suggested, however, I liked the script from the other thread (which I forgot to link to in my original post) here it is
I like the fact that I can roll it out to other record producers without too much issue because it finds all the variables through it and I don't have to custom each record producer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2018 04:41 AM
Hi Brendan,
So were you able to achieve your requirement? If yes then you can mark the answer as correct and helpful. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader