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

Vishnu Prasad K
Giga Guru

Hi Enkhdalai,

 

Current object can't be used in Fix scripts. Do a GlideRecord query on the table which you want to update and then update the values. It's more of a background script with extended capabilities.

Instead of current you should use your GlideRecord object

Hi Vishnu, 

what i am using is this:

var gr = new GlideRecord('cmdb_ci_server');


gr.EncodedQuery('...');
gr.addQuery();
gr.query();

while(gr.next()){

...

In the gr.EncodedQuery('...'); line, i need to use startswith condition on ip address. How do i accomplish this? 

 

Thanks in advance.

Hi,

you can make the filter as shown below

find_real_file.png

 

then run it and copy the query

 

find_real_file.png

 

And then use the copied query and use it on the Encoded Query.

 

-Anurag

-Anurag