addEncodedQuery does not work in business rule..

Sjoshi2
Mega Contributor

I wanted to change risk from 'none' or 'empty' to 'Low' in change request module.I did it with this code for background script..

var querystring = "risk=5^ORrisk=";

var gr = new GlideRecord('change_request');

gr.addEncodedQuery(querystring);

gr.query();

while(gr.next())

{

        gr.setWorkflow(false);

        gr.setDisplayValue('risk','4');

        gr.update();

}

and it worked..

now while writing it in business rule with when to run option selected as 'before insert or update' and in script I wrote

var querystring = "risk=5^ORrisk=";

var gr = new GlideRecord('change_request');

gr.addEncodedQuery(querystring);

gr.query();

while(gr.next())

{

        gr.setDisplayValue('risk','4');

        gr.update();

}

but it didn't work out..however I kept it simple and wrote..

if(current.risk == '5' || current.risk =='')

current.risk=4;

and it worked...

Does addEncodedQuery work in business rule or not?????

7 REPLIES 7

If that helped you then please mark the answer as correct


sergiu_panaite
ServiceNow Employee
ServiceNow Employee

Change the while from:



while(gr.next())


{


      gr.setDisplayValue('risk','4');


      gr.update();


}


to:



while(gr.next())


{


      gr.risk = 4;


      gr.update();


}



Regards,


Sergiu


Hi Sergiu,



Thank you..