We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Trying to Update Requested Item State based on Catalog Task State

chaitanyakumar
Tera Expert

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

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee

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


chaitanyakumar
Tera Expert

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


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


chaitanyakumar
Tera Expert

Made both changes to Business Rule. Still not working