- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 05:20 AM
I have a list collector variable called asset which refers to hardware table. I have to populate the assignment group based on the support group of the asset selected.
I have written the below code in the workflow. But it is not working
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 07:03 AM
list collector will only multiple assets.
so assignment group on RITM should be populated with which asset's support group?
if any 1 asset for which support group is not empty then use this script
var assets = current.variables.asset.toString();
var assetGr = new GlideRecord("cmdb_ci_hardware");
assetGr.addQuery("sys_id", "IN", assets);
assetGr.addNotNullQuery("support_group");
assetGr.setLimit(1);
assetGr.query();
if (assetGr.next()) {
current.assignment_group = assetGr.support_group;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 05:40 AM
Hi @SHALIKAS
I don't understand the requirement here .
List collector contains list of assets.but assignment group is a reference field which stores single record.
Could you please give more context on your requirement.
I also reviewed your script, you need change few things. Ex variable references are incorrect.
Corrected script:
var assets=current.variables.asset;
var assetArr=assets.split(',');
gs.log("asset are"+assetArr);
for(var i=0;i<assetArr.length;i++)
{
var assetGr=new GlideRecord('cmdb_ci_hardware');
if(assetGr.get(assetArray[i]))
{
if(assetGr.getValue'(support_group)'!='')
{
current.assignment_group=assetGr.getValue('support_group');
break;
}
}
}
Regards ,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 06:48 AM
Hello @SHALIKAS ,
Here is an improved version of the script:
var assets = current.variables.asset,
assetGr = new GlideRecord('cmdb_ci_hardware');
assetGr.addQuery('sys_id', 'IN', assets);
assetGr.addNotNullQuery('support_group');
assetGr.query();
if (assetGr.next()) {
current.assignment_group = assetGr.getValue('support_group');
}
Depending on what kind of Workflow activity you are using this script in, you will also have to add the following line at the end:
current.update();
But as @J Siva already mentioned, this will only makes sense if picking a random assignment group is acceptable.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 07:03 AM
list collector will only multiple assets.
so assignment group on RITM should be populated with which asset's support group?
if any 1 asset for which support group is not empty then use this script
var assets = current.variables.asset.toString();
var assetGr = new GlideRecord("cmdb_ci_hardware");
assetGr.addQuery("sys_id", "IN", assets);
assetGr.addNotNullQuery("support_group");
assetGr.setLimit(1);
assetGr.query();
if (assetGr.next()) {
current.assignment_group = assetGr.support_group;
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader