The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to update state in sc_request table?

Radhika11
Tera Contributor

Hello,

For learning purposes, I'm trying to update state from "Work in Progress" to "Open" state in sc_quest table. Here is the code, but it doesn't seem to be working. It can update to other state, but not Open state.  Any advise would be appreciated. 

var gr = new GlideRecord('sc_request');
if(gr.get('number','REQ0025275')){
gr.state = 1 //Set State Open
gr.update();
}

 

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

There is no issue in your script. It is working correctly for me in my PDI.

See below:

Initially this Request state was in Work In Progress as shown below:

find_real_file.png

Now I have executed your script from background and it has updated it correctly as shown below:

find_real_file.png

find_real_file.png

Final Result update done to Open from Work in progress:

find_real_file.png

Couple of things you need to note here is if State is not visible on the Request form, then add it in List view as shown in my screenshot above.

Say if still it does not work then use this version of script below:

var gr = new GlideRecord('sc_request');
if(gr.get('number','REQ0010018')){
gr.state = 1 //Set State Open
gr.setWorkflow(false);
gr.update();
}

This will definitely work. Have tried it and for me both scripts are working.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi Radhika,

There is  an OOTB Business Rule running on the sc_request table named Mark Request Closed that updates the state field based on the request_state or stage, but this update only happens if the state of the Request is 1 (Open).  You'll want to modify line 19 on this Business Rule to also include 2 (Work in Progress), and maybe even -5 (Pending) if you are using that request state

if(current.state == 1 || current.state == 2){

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Hi Sandeep,

I was running the code from scripts background.  Could you please give it a try and let me know if it is working for you for not.  Thanks

shloke04
Kilo Patron

Hi,

There is no issue in your script. It is working correctly for me in my PDI.

See below:

Initially this Request state was in Work In Progress as shown below:

find_real_file.png

Now I have executed your script from background and it has updated it correctly as shown below:

find_real_file.png

find_real_file.png

Final Result update done to Open from Work in progress:

find_real_file.png

Couple of things you need to note here is if State is not visible on the Request form, then add it in List view as shown in my screenshot above.

Say if still it does not work then use this version of script below:

var gr = new GlideRecord('sc_request');
if(gr.get('number','REQ0010018')){
gr.state = 1 //Set State Open
gr.setWorkflow(false);
gr.update();
}

This will definitely work. Have tried it and for me both scripts are working.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi Shloke,

The script you provided works. 

If I remove this line of code, it did not work.  Can you explain what this code does?  Thank you

gr.setWorkflow(false);