How to transform data into multi row variable set of record producer by using transform map script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 09:28 AM - edited 01-21-2024 10:27 PM
Hi
We have a requirement to submit a record producer with a single MRVS by using transform map script.
How do we transform string type data into MRVS format and how to submit the record producer automatically with the script? Could you please help me with the code.
Which transform map script to use?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 07:45 PM
Hi,
What is the purpose of submitting record producer through script?
Ultimately record producer creates a table in target table so you can use transform map for your target tables and insert the data.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 10:26 PM
Sure, I can help you with that. Here are the steps you need to follow:
1. First, you need to create a Record Producer. In ServiceNow, a Record Producer is a type of a catalog item that allows users to create task-based records from the Service Catalog. For example, you can create a change record or problem record using record producers.
2. In your case, you want to submit a record producer with a single MVRS (Multi Value Reference Selector). This means you need to create a Record Producer with a variable of type 'Reference' and 'Multiple' checked.
3. Now, coming to the transformation of string type data into MVRS format, you can use a Transform Map script. A Transform Map is a set of field maps that determine the relationships between fields in an import set and fields in an existing ServiceNow table.
4. Here is a sample script that you can use in your Transform Map:
javascript
(function transformEntry(source, target, map, log, isUpdate) {
var mvrs = source.u_mvrs.toString(); // Assuming u_mvrs is your source field
var mvrsArray = mvrs.split(','); // Splitting the string into an array
for (var i = 0; i < mvrsArray.length; i++) {
var gr = new GlideRecord('table_name'); // Replace 'table_name' with your actual table name
gr.addQuery('field_name', mvrsArray[i]); // Replace 'field_name' with your actual field name
gr.query();
if (gr.next()) {
target.u_mvrs = gr.sys_id; // Assuming u_mvrs is your target field
}
}
})(source, target, map, log, action);
5. This script will transform your string type data into MVRS format by splitting the string into an array and then querying each value in the array against a table in ServiceNow. If a match is found, it will set the sys_id of the matching record to your target field.
6. To submit the Record Producer automatically with the script, you can use the GlideRecord 'insert' method. Here is a sample script:
javascript
var gr = new GlideRecord('sc_req_item'); // Replace 'sc_req_item' with your actual table name
gr.initialize();
gr.u_mvrs = 'value'; // Replace 'value' with your actual value
gr.insert();
7. This script will create a new record in the specified table with the specified value.
Please replace 'table_name', 'field_name', and 'value' with your actual table name, field name, and value. Also, make sure to replace 'u_mvrs' with your actual field name if it's different.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 10:12 PM
Sorry, Its MRVS multi row variable set