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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2014 08:08 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2014 09:30 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2014 06:03 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2015 04:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2015 05:44 AM
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