Business Rule / Client Script to update the Asset install_status field

danielbartholom
Mega Expert

Hi there,

I have a simple question however I am not sure how simple the process would be?

I am looking for a Business Rule or Client Script to do the following:

When the Install Status field on a CI record is changed to Operational, the State of the linked Asset will change to In use

I have looked as the Asset-Ci Syncing and this did not help as there is more values in install_status than Operational Status

I have also tried some scripting using GlideRecord. I am a little stumpt and was wondering if there is a simply way to achieve this goal?

Thanks

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

create a business rule on ci table. 

When: After insert and update

Conditions: Install Status change To Operational

Script:

var ast= new GlideRecord("alm_asset");

ast.addQuery("ci",current.getValue("sys_id"));

ast.query();

while(ast.next()){

ast.install_status='1';//choice value of in use

ast.update();

}

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Daniel,

You can have onChange client script on the table and set the value in the state field.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi thanks for your reply,

 

Just to be clear that the Status Operation field and State field is on two different tables. Can you kindly provide a working script that would link them both?

 

So, when the Operational Status field is changed to Operational (cmbd_ci table), the State field on the Asset (alm_hardware) is changed to In use.

 

 Would I need a GlideRecord query to something on the lines of:

 

 

If text in the CI field (alm_hardware) is the same as the name of the CI

Perform action

  

Abhinay Erra
Giga Sage

create a business rule on ci table. 

When: After insert and update

Conditions: Install Status change To Operational

Script:

var ast= new GlideRecord("alm_asset");

ast.addQuery("ci",current.getValue("sys_id"));

ast.query();

while(ast.next()){

ast.install_status='1';//choice value of in use

ast.update();

}

You have cracked it thank you so much....so just to confirm the following line in the script

 

ast.addQuery("ci",current.getValue("sys_id"));

 

I am assuming this is querying the alm_asset table to look for the current CI sys_id i am changing the operational status is the same one populated in the CI field on the Asset record....is that right?

I was originally scripting the following ast.addQuery('ci', current.cmdb_ci.name);

But now I see this actually means nothing as the getValue and sys_id does all the work for you.

Thanks again for your help.