- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 03:43 PM
Hi,
I'm trying to pass over Catalog Variables from a Record Producer to show in the 'Notes' in the Incident.
Just like these posts https://community.servicenow.com/thread/156305 and https://community.servicenow.com/thread/149636
I've added the below script in the Record Producer script section and get syntax error of: WARNING at line 2: Bad for in variable 'key'.
var wn = 'Variables:';
for (key in current.variables) {
var v = current.variables[key];
wn += '\n' + v.getGlideObject().getQuestion().getLabel() + ':' + v.getDisplayValue();
}
current.work_notes = wn;
When I run the form, it only displays in notes
'Variables:'
One of the form Variable Name is: onboard_name and another is onboard_job.
Knowing that straight copying online scripts to try suit my requirements won't always work, are you able to point me in the right direction to customize it to what I am attempting to do?
I need to display Catalog Variables in a record producer to appear in the 'Note' Section of an Incident as if they were on the form.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 11:26 PM
Hi Tony,
You can also use:
var wn = 'Variables:';
for (var key in producer)
if (producer[key]) {
if (key.search('onboard') != -1) {
wn += '\n' + key + ':' + producer[key];
}
}
current.work_notes = wn;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 03:49 PM
Hi Tony,
Unless you've declared it somewhere else that isn't in the code you copy/pasted above, I believe you will need to declare the variable 'key' in your for-loop.
i.e.
var wn = 'Variables:';
for (var key in current.variables) {
var v = current.variables[key];
wn += '\n' + v.getGlideObject().getQuestion().getLabel() + ':' + v.getDisplayValue();
}
...
Bear in mind, I haven't included or vetted the rest of your script because I don't know how complete it is. But that issue stands out as a possible cause of your problem.
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 11:58 PM
Hi Tony,
Try this:
var wn = 'Variables:';
for(var key in producer)
wn += '\n' + key + ':' + producer[key];
current.work_notes = wn;
You need to filter out variables that you don't want on incident.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 04:27 PM
Hi Deepak,
Thank you for your response, that helped. Do You mind if you can assist with the filtering? We are trying to filter only Variables that contain the work 'onboard'
is the below code the best way to filter to only show the variables we are after?
var wn = 'Variables:';
for (var key in producer)
if (producer[key]) {
if (key == '%onboard%') {
wn += '\n' + key + ':' + producer[key];
}
}
current.work_notes = wn;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-10-2016 11:26 PM
Hi Tony,
You can also use:
var wn = 'Variables:';
for (var key in producer)
if (producer[key]) {
if (key.search('onboard') != -1) {
wn += '\n' + key + ':' + producer[key];
}
}
current.work_notes = wn;