
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2019 05:12 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2019 08:25 AM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2019 05:15 AM
Hi,
You cannot update asset in this way, you have to write another glide record to get to that asset record, and then update install status there.
Update on dot walk doesnt work.
-Anurag

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2019 05:20 AM
Something like this should work.
var gr = new GlideRecord('clm_m2m_contract_asset');
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2019 06:17 AM
Hi Brian,
I had something similar to this originally:
//var exContract = new GlideRecord('ast_contract');
//exContract.addQuery('state','Expired');
//exContract.query();
//while (exContract.next()){
//var assets = new GlideRecord('alm_asset');
//assets.addQuery('lease_id',exContract.number);
//assets.query();
//while (assets.next());{
// assets.install_status = '7';
//}}
I don't think it was this version but one of them resulted in 2000 new duplicate assets being created. I assumed it was the nested GlideRecord.
I will give your code a go and let you know. 😉
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-12-2019 06:31 AM
you should add asset.update() in the script above.