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 03:58 PM
Hello Chaitanya,
You mentioned that you need to update the requested item table when there is a change in the task table. However, you mentioned in above notes that you have created this BR on sc_req_item table. The BR in that case needs to be on sc_task table.
Please adjust the script accordingly and try once.
http://wiki.servicenow.com/index.php?title=Business_Rules_Best_Practices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2016 04:42 PM
Hi Pradeep,
Sorry I was confused. I have updated the Business rule with Following Script but still not working
When to Run:
short description = HRIS Request
Script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id', current.request);
gr.query();
if(gr.next()){
gr.state = 21;
gr.update();
}
})(current, previous);
Thanks,
Chaitanya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2016 04:54 PM
Please update this below line
gr.addQuery('sys_id', current.request_item);
and also the business rule condition should be state changes to Work in Progress
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-22-2016 05:02 PM
Made both changes to Business Rule. Still not working