addEncodedQuery does not work in business rule..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2015 02:18 AM
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?????

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2015 03:06 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2015 01:07 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2015 01:55 AM
Hi Shreya,
Make the business rule with when to run option selected as 'after insert or update' and try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2015 02:20 AM
Hi Ajai,
Thank you..