- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 04:09 AM
I am in need of fix script to change all hardware assets that has state of Allocated-primary system, and Allocate-secondary system and change it to state in use.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 04:13 AM
Hi @Ralton Stewart!
The code should look something like this:
// Query for hardware assets with the specified states
var hardwareAssets = new GlideRecord('alm_hardware');
hardwareAssets.addQuery('state', 'IN', ['Allocated-primary system', 'Allocate-secondary system']);
hardwareAssets.query();
// Update each hardware asset to the 'In use' state
while (hardwareAssets.next()) {
hardwareAssets.state = 'In use';
hardwareAssets.update();
gs.info('Updated hardware asset ' + hardwareAssets.getDisplayValue() + ' to In use');
}
gs.info('Script completed');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2023 04:23 AM
In same manner
- Get all the asset in list view.
- Filter as per your requirment.
- Select the state field and down arrow to select all records in on go.
- Update state.
But before you update, please check what state will reflect in CI for respective Asset. See the 2 nd table and proced further.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 04:06 AM
Thanks for this do you know if this method will
slow down the instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2023 04:13 AM
Hi @Ralton Stewart!
The code should look something like this:
// Query for hardware assets with the specified states
var hardwareAssets = new GlideRecord('alm_hardware');
hardwareAssets.addQuery('state', 'IN', ['Allocated-primary system', 'Allocate-secondary system']);
hardwareAssets.query();
// Update each hardware asset to the 'In use' state
while (hardwareAssets.next()) {
hardwareAssets.state = 'In use';
hardwareAssets.update();
gs.info('Updated hardware asset ' + hardwareAssets.getDisplayValue() + ' to In use');
}
gs.info('Script completed');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 02:18 AM
@Ralton Stewart Filter the records in the table as per the state you want to change (is one of filter). Copy the Query from the filter
eg(install_statusIN2,6)
var hwAsset = new GlideRecord('alm_asset');
hwAsset.addEncodedQuery("paste query from filter");
hwAsset.query();
while(hwAsset.next()){
hwAsset.state = 'backend value of the choice In use';
hwAsset.update();
}