The Zurich release has arrived! Interested in new features and functionalities? Click here for more

automatically sync a field's value between two tables in ServiceNow cmdb_ci and cmdb_ci_azure

VaibhavM
Tera Contributor

I want to synch operational_status field between two tables in ServiceNow cmdb_ci_net_gear and cmdb_ci_azure. Name(name) is a common in both table . cmdb_ci_azure is a parent, cmdb_ci_net_gear is a child


ex. when I change the state (operational_status ) to retired (backend value=3) in  cmdb_ci_azure table  then need to change state (operational_status ) to retired (backend value=6) in cmdb_ci_net_gear  table as well .

 

but the condition is the class in cmdb_ci_azure  table should be one of class_windowos or class_linux.

 

I have already wrote business rule but its not working as expected

BR is as below- 

 

 

filter conditions  :

operational status changes to retired and class is windows or linux

 

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

    if ((current.sys_class_name == 'class_windowos ' || current.sys_class_name == 'class_linux') & current.operational_status==3)
    {
 var serverName = current.name;
 gs.info('dns name is'+ serverName);
 
var dnsrc=new GlideRecord('cmdb_ci_net_gear  ');
        dnsRC.addQuery('name', serverName);
        dnsRC.query();

        while (dnsRC.next()) {
            dnsRC.setValue('operational_status','6');
            dnsRC.operational_status=6;


            dnsRC.update();

        }

    }
})(current, previous);
 
 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@VaibhavM 

so what debugging did you do? what are your findings?

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

I have done gs.info to fetching server name but its not coming in logs