SetValue not working

Andrew Bettcher
Kilo Sage

Hello,

I'm trying to create a script that can run early in the morning to set all of the assets that are associated with expired contracts to "Retired" status (we get our contract and asset details from a 3rd party system that insists on adding a new unique reference even though it's the same actual asset and so this is to avoid duplicates appearing on searches - search fields are set to exclude retired assets).

I'm banging my head against the wall here. It should be nice and easy.

I started defining the contracts via a glideRecord and then grabbing the associated assets but that didn't work so I change it to use the clm_m2m_contract_asset records instead. It finds the records OK but I just can't get it to set the related assets install status to retired.

Here is the latest iteration:

 

var gr = new GlideRecord('clm_m2m_contract_asset');
gr.addQuery('contract.state','expired');
gr.query();

while (gr.next()){
	gr.setValue('asset.install_status', 7);
	gr.update();
}

 

I've tried every permutation of the "setValue" line that I can think of including simply asset.install_status = 7. No dice.

(7 is the value for "Retired").

What's going wrong here?

1 ACCEPTED SOLUTION

I'm not sure. I just modified the script so I could run it against one that is expired in my PDI demo data and it worked.  Below is the code ran in the script background.

var gr = new GlideRecord('clm_m2m_contract_asset');
gr.addQuery('contract.number', 'CNTR0009009')
//gr.addQuery('contract.state','expired');
gr.query();

while (gr.next()){
	var asset = new GlideRecord('alm_asset');
	asset.addQuery('sys_id', gr.asset);
	asset.query();
	if (asset.next()){
		asset.setValue('install_status', 7);
		asset.update();
	}
}

 

View solution in original post

10 REPLIES 10

Rajesh Kannan G
ServiceNow Employee
ServiceNow Employee

 

Do you want to retire an asset which has both expired and active contracts?

Regards,

Rajesh