Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trying to Copy Variables in a record producer to appear in the Incident Notes.

tt565
Kilo Contributor

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.

1 ACCEPTED SOLUTION

deepakgarg
ServiceNow Employee
ServiceNow Employee

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;


View solution in original post

7 REPLIES 7

Hi Tony,



If that solved your problem, please mark any of the answer correct and close the thread. That might also help other people facing the same problem.


tt565
Kilo Contributor

Hi Deepak,



Is there a way to convert the sys_id to the value names for the fields,


I have reference fields I am trying to call using the code above, and when it pulls the data through, it shows as a Sys_id and not the value they have selected from the reference.



EG. The reference variable is pulling from the Department Table, where the user can select a department, When the form is complete and pulled through to the notes, it displays as a sys_id and not the value they selected.



and where can I find all information in 'producer'?



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;



much appreciated.


deepakgarg
ServiceNow Employee
ServiceNow Employee

Hi Tony,



You can use:



var wn = 'Variables:';


for (var key in producer)


      if (producer[key]) {


              if (key.search('onboard') != -1) {


                      wn += '\n' + key + ':' + producer[key].getDisplayValue();


              }


      }


current.work_notes = wn;