Trying to Update Requested Item State based on Catalog Task State
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2016 03:51 PM
Hi All,
"
I have requirement that update the Requested Item state to "Active" when one of the Request Item catalog task ( for HRIS Request) state changes to Work In Progess. I have written After Update BR on sc_req_item but looks like it's not working. Here is my BR script
Business Rule:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.addQuery('state',2);
gr.addEncodedQuery('short_description=HRIS Request');
//gr.orderBy('number');
gr.query();
while(gr.next()){
//of ( gr.number == current.number ) {
current.state = 21;
current.update();
// execute code
// since we ordered by the number, this is the very first sc_task of the RITM
}
// Add your code here
})(current, previous);
Am i missing anything here. Can anyone help me on this BR
Thanks,
Chaitanya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2016 05:04 PM
Instead of if can you please update it to while
while(gr.next()){
gr.state = 21;
gr.update();
}
I had this problem before where gr.update() didn't work in if loop.
Can you also tell how you are testing it? Just want to know if you missing something