- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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?
-------------------------------------------------------------------------------------------------------------------------------------------------
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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 weeks ago - last edited 3 weeks ago
Try below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
There is a space between new and GlideRecord. I changed the value of x to 1000 and I still received the same results. Any other suggestions please make it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks 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 weeks ago
Pointing me to the sys_choice table and the following line was the best help. Thanks,
asset.setValue('substatus', 'pending_repair');// choose required substatus
was the greatest of help. Thanks,