The CreatorCon Call for Content is officially open! Get started here.

Sync two fields

javis
Giga Expert

Hey everyone, I'm looking into writing a BR to keep the vales of two fields in sync: Operational status and Install Status, they are both on the cmdb_ci table. I'm having a hard time trying to figure out what the best way to do this is. Screenshots below:

find_real_file.png

 

find_real_file.png

For example if Operational Status changes to Non-Operational then Install Status is absent. 

 

This can't be done using the actions tab, any suggesstions or tips?

Thanks in advance, 

4 REPLIES 4

Chuck Tomasi
Tera Patron

My first thought is to make this "data driven" as possible. Don't code more than you have to and plan for the future!!!

Create a table that maps the operational status to the install status.

Write a business rule that does a lookup on operational status and sets the appropriate install status.

Now, in the future, when someone changes your options on either list or wants to change the rules, you simply update the date in the table. No coding necessary because all the BR does it a simple lookup.

Thanks Chuck! 

Would you mind giving me a quick example of what this would look like? Do I create field maps for OP status and Install Status? If I create a BR what would the conditions be?

Thanks again! 

Create a simple table (not extended from anything) with two choice fields. Call them the same names as the cmdb_ci fields for simplicity.

In the dictionary for each to get the choices for your new fields from the actual values on the cmdb_ci fields (that way you don't have to replicate the choices and keep them in sync.) See this post and start the video about 7:24.

Populate the new table with your mappings of Operational status -> Install status

Create a business rule something like this... (note this is untested)

Name: Update Install Status

Table: cmdb_ci

Update: true

Insert: true

When: Before

Advanced: true

Condition (the none coding one that uses the condition builder): Operational status | changes

Script: 

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

  // Lookup the record with the operational status matching the current record
  var st = new GlideRecord('YOUR_NEW_TABLE_HERE');
  if (st.get('operational_status', current.operational_status)) {
    current.install_status = st.install_status;
  }

})(current, previous);