Need to populate assignment group based on list collector variable

SHALIKAS
Tera Guru

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

var assets=current.variables.asset;
var assetArr=assets.split(',');
gs.log("asset are"+assetArr);
for(var j =0;i<assetArr.length;i++)
{
    var assetGr=new GlideRecord('cmdb_ci_hardware');
    if(assetGr.get(assetArray[k]))
    {
        if(assetGr.support_group)
        {
            current.assignment_group=assetGr.support_group;
            break;
        }
}
}
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@SHALIKAS 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

J Siva
Tera Sage

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

Robert H
Mega Sage

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

Ankur Bawiskar
Tera Patron
Tera Patron

@SHALIKAS 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader