Need to set value in MRVS via script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 08:26 AM
Requirement:
We have a multi-row variable set on a form. If the user enters more than 1 row on the MRVS, then create a RITM for each row after row 0.
Development so far:
I've been able to script a solution that will kick off a RITM for each row in the MRVS based on a great article by @Vishal Birajdar (Create multiple RITM under single request dependin... - ServiceNow Community)
The script will create the RITM and what I need is to take data from a row in the MRVS and populate the MRVS on the new RITM
Example:
Bob is requesting software for 4 of his colleagues.
On the software form is a MRVS for Bob to enter the users who are getting the software:
In the example above, 3 new RITMs will be created, started with Abe Lincoln, then Quintin, then Zack.
The script will create the 3 RITMs as expected.
I'm able to grab the data for each user, but my script to set the MRVS in the RITM is no populating via a Run Script in workflow editor.
Here's a snippet of the script that I'm trying to use to populate the MRVS:
var v1 = parseMrvs[i].customer_name.toString();
var v2 = parseMrvs[i].network.toString();
var v3 = parseMrvs[i].business_need.toString();
var v4 = parseMrvs[i].justification.toString();
var v5 = parseMrvs[i].nro_customer.toString();
var v6 = parseMrvs[i].customer_phone_number.toString();
var v7 = parseMrvs[i].customer_email.toString();
gs.info('MM in here line 164');
gs.info('MM RITM sys_id ' + ritmSysId);
gs.info('MM v1 ' + v1);
gs.info('MM v2 ' + v2);
var gr = new GlideRecord('sc_req_item');
gr.get(ritmSysId);
gr.query();
gs.info('MM count: ' + gr.getRowCount());
if (gr.next()) {
var mrvs = gr.variables.u_customer_information;
for (var rc = 0; rc < 1; rc++) {
var newRow = mrvs.addRow();
newRow.setCellValue('customer_name', v1);
newRow.setCellValue('network', v2);
newRow.setCellValue('business_need', v3);
newRow.setCellValue('justification', v4);
newRow.setCellValue('nro_customer', v5);
newRow.setCellValue('customer_phone_number', v6);
newRow.setCellValue('customer_email', v7);
// newRow.customer_name = v1;
// newRow.network = v2;
// newRow.business_need = v3;
// newRow.justification = v4;
// newRow.nro_customer = v5;
// newRow.customer_phone_number = v6;
// newRow.customer_email = v7;
}
gr.update();
}
The log statements in the script show up perfectly so the data is there.
Here's the kicker:
When I run the code above in a background script, the MRVS will populate perfectly w/ the data (variables) I'm expecting.
So why would the script run in a background script but not a Run Script in Editor?
Any help is greatly appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 04:58 AM - edited 11-28-2023 05:13 AM
See script above