
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
05-09-2021 10:17 PM - edited 08-12-2024 09:05 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
When working with Record Producers, you probably have used the Map to field option on variables. When applying Variable Sets on Record Producers, 'somehow' the Map to field function disappears?! Well actually not 'somehow', it's on purpose. Two years back already I encountered this way of working myself and came up with a workaround. So not new really 🙂 Though because of recent Community questions on exactly this topic, I thought let's write it all out!
Map to field on Variables
Let's just grab the Docs description of Map to field:
"Maps the variable to a specific field on the table for the record producer. This field appears if the variable belongs to a record producer."
To make it more visible:
On Record Producers, there's a Map to field checkbox visible (hidden for Catalog Items). When the checkbox is ticked, the "Field" field is displayed with which you can select the field on the table set on the Record Producer. The value of your variable will then be mapped to the selected field upon submitting the Record Producer.
Map to field on Variable Sets
A good practice when working with Catalog Items, Record Producers, is to apply Variable Sets. Variable Sets that contain common artifacts (variables, catalog client scripts, etcetera) used across multiple Catalog Items, Record Producers, etcetera. When it concerns variables and the Map to field option, for Variable Sets this is hidden?!
Well, actually it's not such a strange thing. Also, see for example KB0610341 from HI:
"The system is functioning as designed. A variable set can be attached to any record producer that creates records in any table, so mapping a variable in a variable set to a specific field is not possible. The mapping that takes place between a variable and a field in a table takes place if the variable name matches a field name in the table."
Workaround
So how could we still use or mimic the Map to fields option? Let's just jump right into it:
On Record Producers, there's a Script field available. Within the Script field, amongst others, you could set field values on the created record. For example:
current.short_description = producer.issue_description;
The code above simply fills the short_description field on the created record from the Record Producer, with the value of variable project_description.
So for example, you've got variables like "Requested for" [Reference], "Urgency" [Select Box], "Issue description" [Single Line Text]. How can we still map these on our Record Producer for the Incident table?
Filling the Script field with code like below would do:
Note: When having the exact same script as described above, you might consider adding this script to a Script Include. From the Record Producer Script field, then only calling the Script Include. Obviously for maintainability! Only one place to maintain this code/logic.
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Platform Architect @ Quint Technology
2x ServiceNow Developer MVP
2x ServiceNow Community MVP
---
- 19,568 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hey Mark!
Big thanks for this, I tried it out and it worked! Thanks as well for all of the assistance you have provided within this community!
Justin
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for the article.
My requirement is to map Summary(u_summary) and Details(u_details) in the record producer with Short description and Description respectively.
Below is the code for it.
current.short_description = producer.u_summary;
current.description = producer.u_details;
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I am having difficulty working with DateTime fields in the script. I am unable to get the value to populate in the record field despite using countless GlideDateTime methods to format the date for insert. Any tips?