- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2016 08:01 PM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2016 09:38 AM
Pass in the comma separated sys_id's.
cart.setVariable(item, 'os', 'sys_id1,sys_id2,sys_id3');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2016 08:08 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2016 09:38 AM
Pass in the comma separated sys_id's.
cart.setVariable(item, 'os', 'sys_id1,sys_id2,sys_id3');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2016 01:52 PM
Thanks Guys, both solutions worked