How to populate list collector variable on a business rule

johannes5
Giga Expert

Hi ServiceNow Community Developers,

Is there a way to populate a list collector variable via business rule when dynamically creating requested items (RITMs). For instance I have the following example that I got from the wiki which I have used to create RITMs from the asset table using a business rule.

var cartId = GlideGuid.generate(null);

var cart = new Cart(cartId);

var item = cart.addItem('e46305bdc0a8010a00645e608031eb0f');

cart.setVariable(item, 'os', 'Linux Red Hat');

var rc = cart.placeOrder();

gs.addInfoMessage(rc.number)

This example works fine for most of the RITMs that I have had to dynamically create so far however I have a requirement to dynamically create an RITM via business but this time one of the variables that I have to populate is a list collector variable. So basically my question is if the 'os' variable from the example I provided above was a list collector variable how would I populate it? Please advise.

Thanks,

Johannes

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Pass in the comma separated sys_id's.



cart.setVariable(item, 'os', 'sys_id1,sys_id2,sys_id3');


View solution in original post

3 REPLIES 3

jake_mckenna
ServiceNow Employee
ServiceNow Employee

Normally with list collectors you would need to pass in the sys_id of the items you want to populate in that list. So instead of using the display value you would need to pass in that value.


Abhinay Erra
Giga Sage

Pass in the comma separated sys_id's.



cart.setVariable(item, 'os', 'sys_id1,sys_id2,sys_id3');


Thanks Guys, both solutions worked