background script to close the ritm?

lakng
Tera Contributor

please someone provide me the background script to close only the targeted RITM records.

not all in sc_req_item table/ sc_request table

i will have a few RITM record numbers.

through background script i have to close only given RITM and REQ, not for remaining records or workflow.

8 REPLIES 8

Harsh Vardhan
Giga Patron

try with below code. now you can add your ritm number which i had added some sample number. 

 

var gr = new GlideRecord('sc_req_item');

gr.addQuery('number','IN','RITM0233941,RITM0233942,RITM02339413');

gr.query();

while(gr.next()){

gr.state= 3;

gr.update();

}

Mark Roethof
Tera Patron

Hi there,

Question: why would you like to close these records this way? I mean, if your workflow is setup correctly, the approval and tasks have been handled: the RITM should be closed automatically. When all RITM's have been handled, the REQ should be handled automatically.

So why scripting the closure?
Is this a one time thing?
Are they in a state Closed though the active flag still true?
Do you have a structural issue in your instance?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Ankur Bawiskar
Tera Patron

Hi,

try this background script to close RITM and request

also use setWorkflow(false) to avoid triggering any business rules on those 2 tables

you should have the list of RITM numbers with yo

var ritmRec = new GlideRecord('sc_req_item');
ritmRec.addQuery('number','IN','RITM000123,RITM000124,RITM000125');
ritmRec.query();
while(ritmRec.next()){
ritmRec.state= 3;
ritmRec.setWorkflow(false);
ritmRec.update();

var reqRefRecord = ritmRec.request.getRefRecord();

reqRefRecord.state = 3;
reqRefRecord.setWorkflow(false);
reqRefRecord.update();

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Good add on the workflow, I had this scenario based on a user rejecting the request in error which had several requested items in it.

Thanks again