Alm_asset cannot access state or substate in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11 hours ago
In "Scripts - Background" I pasted the code below the dotted line. I really want to update the substate field but I see when I run the script below it comes up undefined. Increasing the size of x does not matter. I tried to do an update based on what Google's AI told me but it did not work. I even tried a setValue but it did not work or give me an error. Can anyone help me?
-------------------------------------------------------------------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago
Try below:
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Get the substatus choices from sys_choice table-
var asset = new GlideRecord('sys_choice');
asset.addEncodedQuery('nameSTARTSWITHalm_asset^element=substatus^language=en');
asset.query();
while (asset.next()) {
gs.print("state: " + asset.value);
}
then decide which substatus you want to update then use below script:
var asset = new GlideRecord('alm_asset');
// Add conditions as needed, e.g.:
// asset.addQuery('state', 'in_use');
asset.setLimit(100); // Safety limit
asset.query();
var count = 0;
while (asset.next()) {
asset.setValue('substatus', 'pending_repair');// choose required substatus
asset.update();
count++;
gs.print('Updated: ' + asset.number);
}
gs.print('Total updated: ' + count);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @ppicazo1 ,
Backend name of the SubState field is sbustatus
replace substate with substatus and run the script again
var assetUnAssign = new GlideRecord('alm_asset');
assetUnAssign.query();
var x = 0;
while (assetUnAssign.next())
{
gs.print(assetUnAssign.substatus);
x++;
if (x > 8)
break;
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya