Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Hardware Asset update

Ralton Stewart
Tera Guru

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.

 

 

 

 

1 ACCEPTED SOLUTION

Alex Tod1
Kilo Sage

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');

View solution in original post

5 REPLIES 5

Dr Atul G- LNG
Tera Patron

Hi @Ralton Stewart 

 

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.

 

AtulyaLNG_0-1700137348261.pngAtulyaLNG_1-1700137401364.png

 

*************************************************************************************************************
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/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Thanks for this do you know if this method will

slow down the instance.

Alex Tod1
Kilo Sage

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');

Akshata T
Tera Guru

@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();

}