Converting business rule to fix script

Enkhdalai
Tera Expert

I want to convert business rule to fix script. 

Below is the business rule:

(function executeRule(current, previous /*null when async*/ ) {
var ip = current.ip_address;
var ips;

if (current.ip_address.startsWith("192.168.0.")) {

current.u_network_zone = "DC - CDE";
ips = ip.substring(10);
if (ips < 128) {
current.u_dc = "Seoul";
} else {
current.u_dc = "Jukov";
}
current.u_is_connect_to_internet = 0;
current.u_is_use_card_information = 1;
current.u_is_deliver_user_information = 1;
current.u_va_total_score = 2;
}

})(current, previous);

 

What this business rule do is filters CI's ip address and sets some fields value to certain value. 

 

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi,

You can use below script,

var ips,ip;
var grCMDB=new GlideRecord("cmdb_ci_server");
grCMDB.addEncodedQuery("ip_addressSTARTSWITH192.168.0.");
grCMDB.query();
while(grCMDB.next()){
ip = grCMDB.ip_address;
ips = ip.substring(10);
if (ips < 128) {
grCMDB.u_dc = "Seoul";
} else {
grCMDB.u_dc = "Jukov";
}
grCMDB.u_network_zone = "DC - CDE";
grCMDB.u_is_connect_to_internet = 0;
grCMDB.u_is_use_card_information = 1;
grCMDB.u_is_deliver_user_information = 1;
grCMDB.u_va_total_score = 2;
grCMDB.update();
}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

7 REPLIES 7

Hi Enkhdalai,

 

You apply the same filter on CI table as follows

find_real_file.png

 

then right click on the query and copy it as follows

 

find_real_file.png

 

Then paste it within the encoded query.

It will be 'ip_addressSTARTSWITH192.168.0.'

 

 

Abhijit4
Mega Sage

Hi,

You can use below script,

var ips,ip;
var grCMDB=new GlideRecord("cmdb_ci_server");
grCMDB.addEncodedQuery("ip_addressSTARTSWITH192.168.0.");
grCMDB.query();
while(grCMDB.next()){
ip = grCMDB.ip_address;
ips = ip.substring(10);
if (ips < 128) {
grCMDB.u_dc = "Seoul";
} else {
grCMDB.u_dc = "Jukov";
}
grCMDB.u_network_zone = "DC - CDE";
grCMDB.u_is_connect_to_internet = 0;
grCMDB.u_is_use_card_information = 1;
grCMDB.u_is_deliver_user_information = 1;
grCMDB.u_va_total_score = 2;
grCMDB.update();
}

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi Abhijit, this one worked. Thanks a lot.