Copy values from MRVS to RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2019 08:32 AM
Everyone,
I am trying to copy the selected "project" from a Lookup Select Box, within a Multi Row Variable Set, to a Multi Line Text variable called "time_tracker_projects" within the Request Item (RITM). Values within the Multi Row Variable Set are not visible within a report, so I need to copy them to the RITM so they can be visible on a report.
Multi Row Variable Set: time_tracker_hours
Below is a (BEFORE/INSERT) Business Rule I am trying to use, but the values are not getting written to the textbox.
Any ideas?
(function executeRule(current, previous /*null when async*/) {
// Get the Multi Row Variable Set - Time Tracker Hours
var mrvs = current.variables.time_tracker_hours;
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
current.variables.time_tracker_projects += row.project;
}
})(current, previous);
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 11:39 AM
Can you try to print below value from background scripts for that RITM to see if it is giving JSON data or not.
current.variables.time_tracker_hours
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 11:51 AM
Nothing, big fat nothing...
(function executeRule(current, previous /*null when async*/) {
var mrvs = current.variables.time_tracker_hours;
gs.addInfoMessage(mrvs);
var mrvsRowCount = mrvs.getRowCount();
gs.addInfoMessage(mrvsRowCount);
var mrvsJSON = JSON.parse(mrvs);
gs.addInfoMessage(mrvsJSON);
var mrvsJSONLength = mrvsJSON.length;
gs.addInfoMessage(mrvsJSONLength);
for(var k = 0; k < mrvsJSON.length; k++){
var tempJson = mrvsJSON[k];
current.variables.time_tracker_projects += tempJson['project'];
}
})(current, previous);
I just want to write the value(s) for "project" from the MRVS (Multi Row Variable Set) to a variable in the RITM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 12:03 PM
Can you run below code from BACKGROUND scripts, you dont have to submit RITM
replace <sys_id> with any existing RITM that has the mrvs is showing up.
If it prints the records that you have selected in mrvs, I think you might need to move the BR to after
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', '<sys_id>');
gr.query();
if(gr.next()){
gs.info(gr.variables.time_tracker_hours);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2019 12:12 PM
It should show something like sample mrvs data below
*** Script: [ {
"type" : "order",
"user" : "abc.123@example.com",
"first_name" : "abc",
"last_name" : "123",
"work_cell" : "9874561230"
}, {
"type" : "technical",
"user" : "def.456@example.com",
"first_name" : "def",
"last_name" : "456",
"work_cell" : "7894561230"
}, {
"type" : "alternate",
"user" : "ghi.789@example.com",
"first_name" : "ghi",
"last_name" : "789",
"work_cell" : "7894561230"
}, {
"type" : "site",
"user" : "jkl.012@example.com",
"first_name" : "jkl",
"last_name" : "012",
"work_cell" : "1231231234"
} ]