- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 03:34 AM
Hi All,
I am creating catalog using below script and i can able to set the value to the normal variables but i am not able to set value to the MRVS.
Please help me how to set value in the MRVS
var cartId = GlideGuid.generate(null);
var adhoc = new Cart(cartId);
var item = adhoc.addItem('a192a8ba1304ba00d9ff30ded144b02d', 1);
adhoc.setVariable(item, 'servicenow_group_descriptions', 'Test');
var rc = adhoc.placeOrder();
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 05:55 AM
Hello Ramesh,
Try below script with cartJs() APi, I tested, and it is working:
var sn_groups = "d476a4e5073a91104154fa9e7c1ed072";
var servicenow_group_descriptions = "Test";
var business_justification = "Test";
var requested_by_date = "Test";
var arr = [];
var Obj = {};
Obj.sn_groups = sn_groups;
Obj.servicenow_group_descriptions = servicenow_group_descriptions;
Obj.business_justification = business_justification;
Obj.requested_by_date = requested_by_date;
arr.push(Obj);
var adhoc = new sn_sc.CartJS();
var requestDetails = {
"sysparm_id": "a192a8ba1304ba00d9ff30ded144b02d",
"sysparm_quantity": "1",
"variables": {
"requested_for": sn_groups,
"servicenow_group_membership_request": JSON.stringify(arr)
}
};
var cartDetails = adhoc.orderNow(requestDetails);
gs.log(cartDetails);
Thank you,
Ali

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 03:42 AM
Hello,
You need to set MVRS variable set value with JSON data.
For example, if MVRS name is test_mvrs and you have two variables var1 and var2 in the MVRS. Then you can set value in above script as
var tempObj = [];
var obj1 = {}; //This represent one row in MVRS and below are columns in MVRS
obj1.var1 = "value 1";
obj1.var2 = "Value 2";
tempObj.push(obj1);
//You can add multiple rows as above pushing to the array
adhoc.setVariable(item, 'test_mvrs', JSON.stringify(tempObj)); //Set array JSON string as value to MVRS
Thank you,
Ali
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 05:19 AM
Hi Ali,
I am running below script its creating RITM but not setting the MRVS values
var sn_groups = "d476a4e5073a91104154fa9e7c1ed072";
var servicenow_group_descriptions = "Test";
var business_justification = "Test";
var requested_by_date = "Test";
var arr = [];
var Obj = {};
Obj.sn_groups = sn_groups;
Obj.servicenow_group_descriptions = servicenow_group_descriptions;
Obj.business_justification = business_justification;
Obj.requested_by_date = requested_by_date;
arr.push(Obj);
var cartId = GlideGuid.generate(null);
var adhoc = new Cart(cartId);
var item = adhoc.addItem('a192a8ba1304ba00d9ff30ded144b02d', 1);
adhoc.setVariable(item, "requested_for", sn_groups);
adhoc.setVariable(item, "servicenow_group_membership_request", JSON.stringify(arr));
var rc = adhoc.placeOrder();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 05:55 AM
Hello Ramesh,
Try below script with cartJs() APi, I tested, and it is working:
var sn_groups = "d476a4e5073a91104154fa9e7c1ed072";
var servicenow_group_descriptions = "Test";
var business_justification = "Test";
var requested_by_date = "Test";
var arr = [];
var Obj = {};
Obj.sn_groups = sn_groups;
Obj.servicenow_group_descriptions = servicenow_group_descriptions;
Obj.business_justification = business_justification;
Obj.requested_by_date = requested_by_date;
arr.push(Obj);
var adhoc = new sn_sc.CartJS();
var requestDetails = {
"sysparm_id": "a192a8ba1304ba00d9ff30ded144b02d",
"sysparm_quantity": "1",
"variables": {
"requested_for": sn_groups,
"servicenow_group_membership_request": JSON.stringify(arr)
}
};
var cartDetails = adhoc.orderNow(requestDetails);
gs.log(cartDetails);
Thank you,
Ali