Sync operational status and install status on CMDB tables

Madhu5
Tera Contributor

Hi All,

My customer wants a sync between operational status and instal staus for all the choice values present.

Ex:If operational status changed to retired then install_status should get change to retired and vice versa

If install status changes to In maintenance then operational status should also get changed to In maintenance

Please suggest some best approach to do this via script.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use before update BR on the table

Ensure you give correct choice values for both the fields

BR Condition: current.install_status.changes() || current.operational_status.changes()

Single BR to handle both the things

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(current.operation_status.changes()){

		// sync operational to install

		var op = current.operation_status;
		if(op == 'retired')
			current.install_status = 'choice value';

		// add else if 

	}
	else if(current.install_status.changes()){

		// sync install to operational

		var install = current.install_status;
		if(install == 'retired')
			current.operation_status = 'choice value';

		// add else if 

	}

})(current, previous);

Regards
Ankur

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use before update BR on the table

Ensure you give correct choice values for both the fields

BR Condition: current.install_status.changes() || current.operational_status.changes()

Single BR to handle both the things

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(current.operation_status.changes()){

		// sync operational to install

		var op = current.operation_status;
		if(op == 'retired')
			current.install_status = 'choice value';

		// add else if 

	}
	else if(current.install_status.changes()){

		// sync install to operational

		var install = current.install_status;
		if(install == 'retired')
			current.operation_status = 'choice value';

		// add else if 

	}

})(current, previous);

Regards
Ankur

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

Hello Ankur ,

 

I have been trying to create this scenario for each run whenever i am updating the values manually BR is getting executed and running fine .
But when a CI gets updated after Discovery this BR is not executing i.e. in case i am updating the Operational status to retire manually its updating the Install status to Retire but if Discovery is running and it updates the value of Install status to retire the operational status is not in sync .
Any idea on this scenario . Do let me know 

Thank you

This was super helpful, one thing to note it's 

operational_status

not operation_status

Vladimir Yordan
Tera Contributor

Hello fellow contributors! I've encountered the same situation and here is my proposed solution:
First, one would need an agreement on Install status to Operational status mapping, here is a possible one:

Cmdb_ci install status labelValueOperational Status MatchValueOP Status Label
In Stock6Ready5Ready
Installed1Operational1Operational
Pending Repair5Repair in Progress3Repair in Progress
Retired7Retired6Retired
Pending Install4Non-Operational2Non-Operational
Absent100Non-Operational2Non-Operational
On Order2Non-Operational2Non-Operational
Stolen8Non-Operational2Non-Operational
In Maintenance3Non-Operational2Non-Operational

 

So, example If a Computer CI is changed from "Installed" to "Retired", its Operational Status changes to "Retired". 
 
Create a Business Rule with the following Attributes:
Table: [CMDB_CI_Computer]

BR: on Before, Insert + Update
Condition: current.install_status.changes()
example Script:

(function executeRule(current, previous /*null when async*/) {

if (current.install_status == 7){
    current.setValue("operational_status",6);
}
else if (current.install_status == 1){
    current.setValue("operational_status",1);
 

//and write it so on for all the mappings..

 

)(current, previous);