The CreatorCon Call for Content is officially open! Get started here.

Record producer to populate a field in the new record based on its own field value, not a variable

valkyrichek
Tera Expert

We have added a custom field on the record producer table and would like a corresponding field on the destination table to be populated from it. The problem is that because it's not a variable, but an actual field, I cannot either map it or access it using "producer.<variable>" notation in the "script" field. And the "current" object in the script refers already to the newly created record... How can I actually access the information from the record producer itself?

I ended up creating a hidden variable and populating its value with a client script, but there must be a simpler way?

4 REPLIES 4

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I don't think you have access to the current record producer as an object. You would need to access it via gliderecord query. Something like:



var recProd = new GlideRecord('sc_cat_item_producer');


if (recProd.get('<sys_id of your record producer>')) {


      current.incidentfield = recProd.recordproducerfield;


}



Although if you're going to hardcode a sys_id in there you might as well just save some lines of code and hardcode the value.


Thanks, Brad. Actually, I wanted to avoid hard-coding the sys_id, because I have almost a 100 identical record producers with the only difference in that one field. So I wanted to use the same script for all of them. I ended up placing a "hidden" variable on the form and populating it with a client script.


valkyrichek
Tera Expert

Thank to Mark Stanger for sharing another elegant solution to a similar problem here http://www.servicenowguru.com/reporting/identify-servicenow-record-producer-create-record/ [Identify which ServiceNow Record Producer was used to create a record]


It is also a more universal one - I would have used it if I was implementing this functionality now.


ganeshb_
Tera Expert

Hi Valentina,


You can call the script include form the Record producers script.


gs.include("Test");


var setValue = new Test();


setValue.setValues();



And in the script include you can set the target records fields by using:


current.description = producer.comments;


and so on...



Thanks,


Ganesh