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

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