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

Ajai S Nair
Giga Guru

Hi Shreya,



You can use encoded query in Business rule also. I have made a small modification in your script. Please try the below code:



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


var gr = new GlideRecord('change_request');


gr.addEncodedQuery(querystring);


gr.query();



while(gr.next())


{


        gr.risk = 4;


        gr.update();


}


Hi Ajai,



I updated my code..


1) Now I am having 10 records for change request..out of which one is already having a risk value as 'none'..


2)when I create one more record with value of risk as 'none' and I update the record then the first record as I mentioned above gets updated with risk as 'low'. And the second record gets updated when I again make changes to any other record.. It is happening consecutively..


3) All records are not getting updated at the time either when they are created or when they are updated.


Hi Shreya,



Make the business rule with when to run option selected as 'after insert or update' and try.


Hi Ajai,


Thank you..