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

How do i auto-populate the field values from cmdb_ci_service table to cmdb_ci_outage table?

Mark263
Kilo Contributor

Hello all,

I have a field 'Recipients' on cmdb_ci_service table

type : list - referred to user table

my requirement is to dot-walk the field on the Outage table(cmdb_ci_outage). I was able to dot-walk the field just fine but it's not fetching the values from 'Recipients'(cmdb_ci_service).

How can this be achieved? Do i have to write a business rule for this? If yes,plz help me with the code.

1 ACCEPTED SOLUTION

OK, I made a mistake... it happens at 6AM. 🙂

Remove the condition and use this in the script instead. Same assumptions apply.

 

// If cmdb_ci has a value (not null)
if (current.cmdb_ci) {
   // Get the cmdb_ci record
   var ci = current.cmdb_ci.getRefRecord();
   // if the cmdb_ci record is a service
   if (ci.getTableName == 'cmdb_ci_service') {
     // Copy the recipients from the service record to the outage record
     current.u_recipients = current.cmdb_ci.u_recipients;
   }
}

View solution in original post

8 REPLIES 8

Chuck Tomasi
Tera Patron

you will need a business rule to do this. The reason is because Configuration item on cmdb_ci_outage points to cmdb_ci which does NOT contain your list field "Recipients". That exists further down in the class structure. It's just like trying to get caller_id from incident by reference task.

Your business rule will have to do a lookup of the record on cmdb_ci_service if the class is cmdb_ci_service, if not, don't run the business rule. 

At a high level, this is what your BR will look like:

Name: Copy Recipients

Table: cmdb_ci_outage

When: BEFORE

Advanced: true

Insert: true

Update: true // You decide if you want this to run when the outage record is updated

Condition: current.cmdb_ci.getTableName() == 'cmdb_ci_service'

Script:

 

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

  // Copy the value from service to outage
  // Modify field names as appropriate
  if (current.cmdb_ci) {
    current.u_recipients = current.cmdb_ci.recipients;
  }

})(current, previous);

Thank for your reply,

I used the above business rule and its not working.

plz look at the screenshots below.

CI = Email - from cmdb_ci_service table

find_real_file.png

 

Business rule that i have configured

find_real_file.png

 

ci 'Email' selected and it's not populating the values

 

 

find_real_file.png

 

Kindly see if i have to make changes in Business rule

TIA

 

I made some assumptions that may require you to adjust your business rule.

 

Assumption 1: your field on the cmdb_ci_outage table is called u_recipients. If this is incorrect, adjust line 8 in your script.

Assumption 2: The outage recipients is going to populate after you create/update the outage record

 

Step 1: Check to see if the business rule is being triggered. Go to System Diagnostics> Debug Business Rules and repeat the operation. At the bottom of the screen you will see output to tell you if the BR was run or not.

==> indicates the BR script was run

<== indicates the BR script was completed

=== means the BR script was not run because the condition didn't match.

Hi

 

Assumption 1: your field on the cmdb_ci_outage table is called u_recipients. If this is incorrect, adjust line 8 in your script - Yes, It's the same.

find_real_file.png

 

Assumption 2: The outage recipients is going to populate after you create/update the outage record - Yes, I'm creating a new outage record.

I did the debug business rule that you have mentioned, it says that it skipped the business rule as the conditions are not met

find_real_file.png

plz tell me what to do next

TIA