mapping variable set variables to record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 09:50 AM
Hi There,
i have variable set (single row) , i need to map variable set variables to record producer (target table),
I tried this below script but it's not working, any one help
Regards,
Rajesh Gillerla.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 10:00 AM - edited 07-23-2024 10:05 AM
Hi @Gillerla Rajesh ,
Check this community thread which talks about how to map variable set variables : https://www.servicenow.com/community/developer-forum/mapping-multirow-variable-sets-in-record-produc...
You can also try this approach:
For Multi-Row Variable Set:
To map variables from a multi-row variable set, you need to iterate over the rows of the variable set and map them to the target table. Here’s an example:
- Define the multi-row variable set in your catalog item/record producer.
- Use a script to iterate through the rows and map them to the target table.
Here is a corrected script for mapping multi-row variable set variables to a record producer:
// Get the GlideRecord of the multi-row variable set table (e.g., 'u_multi_row_variable_set')
var multiRowVarSet = new GlideRecord('u_multi_row_variable_set');
// Add a query to get the relevant records if needed
multiRowVarSet.addQuery('parent', producer.sys_id);
multiRowVarSet.query();
while (multiRowVarSet.next()) {
// Create a new record in the target table for each row in the multi-row variable set
var targetRecord = new GlideRecord('target_table'); // Replace 'target_table' with your actual table name
targetRecord.initialize();
// Map the variables from the multi-row variable set to the target record fields
targetRecord.field1 = multiRowVarSet.u_variable1; // Replace 'u_variable1' with your variable name
targetRecord.field2 = multiRowVarSet.u_variable2; // Replace 'u_variable2' with your variable name
// Add more fields as necessary
// Insert the target record
targetRecord.insert();
}
Thanks.
Hope it helps.
Mark it helpful and accept solution if my response was useful.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 10:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 10:47 PM
This is also not working