- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 09:24 PM
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();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 06:34 AM
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:
Now I have executed your script from background and it has updated it correctly as shown below:
Final Result update done to Open from Work in progress:
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 09:31 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2022 09:50 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 06:34 AM
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:
Now I have executed your script from background and it has updated it correctly as shown below:
Final Result update done to Open from Work in progress:
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2022 09:32 AM
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);