Populate cart variables of MRVS while creating record from Record Producer

MehakA
Tera Contributor

Hi,

I have created a record producer which creates multiple catalog items. I have used the cart functionality. In one of my catalog items there is MRVS, I want to set one of the variable values for that MRVS. That variable is List collector and while creating the record I am passing the sys id. But the value is not getting populated for that variable in MRVS. Basically, I am not able to set variable value for MRVS through record producer script. I tried 3 ways highlighted as red but no success.

Everything is working fine for other variables other than MRVS variables. Can anyone guide me how I can achieve it. 

 

Here is my code which I have written in script of Record Producer:

 

 
var item;
var cartId1 = GlideGuid.generate(null);
var cart1 = new Cart(cartId1);

        item = '';
        item = cart1.addItem('sys_id', 1); //passed sys id of cat item
        cart1.setVariable(item, 'requested_for', producer.requested_for);
        cart1.setVariable(item, 'action_required', "Modify");        
        cart1.setVariable(item, 'modify_detail', "Group members");
        cart1.setVariable(item, 'justification', producer.business_justification);         
        cart1.setVariable(item, 'id', producer.requested_for); // This id is the list collector variable in MRVS (Method 1)
var rc = cart1.placeOrder();
 
//Set variables in Multi Row Variable Set
(Method 2)
        var mrvsArr = [];        
        mrvsArr.push({
        "id": producer.requested_for
         });
         var mrvsArrJson = JSON.stringify(mrvsArr);
         cart1.setVariable(item, 'members_added', mrvsArrJson); //members_added is MRVS internal name
(Method 3)
        cart1.setVariable(item, 'members_added', '[{"id":producer.requested_for}]');
 
Thanks,
Mehak Arora
1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You cannot set the MRVS value via the Cart API, but you can update the RITM after it's created, and you need to properly concatenate the string when inserting the producer value, and that needs to be inside of quotes which must be escaped from the encapsulating string quotes:

var item = '';
var cartId1 = GlideGuid.generate(null);
var cart1 = new Cart(cartId1);
item = cart1.addItem('sys_id', 1); //passed sys id of cat item
cart1.setVariable(item, 'requested_for', producer.requested_for);
cart1.setVariable(item, 'action_required', "Modify");        
cart1.setVariable(item, 'modify_detail', "Group members");
cart1.setVariable(item, 'justification', producer.business_justification);         
var rc = cart1.placeOrder();

//query RITM and set the MRVS value
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.sys_id);
ritm.query();
if (ritm.next()) {
	ritm.variables.members_added = "[{\"id\":\"" + producer.requested_for + "\"}]";
	ritm.setWorkflow(false);
	ritm.update();
}

 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

You cannot set the MRVS value via the Cart API, but you can update the RITM after it's created, and you need to properly concatenate the string when inserting the producer value, and that needs to be inside of quotes which must be escaped from the encapsulating string quotes:

var item = '';
var cartId1 = GlideGuid.generate(null);
var cart1 = new Cart(cartId1);
item = cart1.addItem('sys_id', 1); //passed sys id of cat item
cart1.setVariable(item, 'requested_for', producer.requested_for);
cart1.setVariable(item, 'action_required', "Modify");        
cart1.setVariable(item, 'modify_detail', "Group members");
cart1.setVariable(item, 'justification', producer.business_justification);         
var rc = cart1.placeOrder();

//query RITM and set the MRVS value
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.sys_id);
ritm.query();
if (ritm.next()) {
	ritm.variables.members_added = "[{\"id\":\"" + producer.requested_for + "\"}]";
	ritm.setWorkflow(false);
	ritm.update();
}

 

Thanks @Brad Bowman  . It worked.

You are welcome!