How can I change state from open to closed incomplete for all request, requested item & catalog task table's records, I need to do this in bulk

rishabh31
Mega Sage

How can I change state from open to closed incomplete for all requests, requested items & catalog task table's records (whose state is currently open), I need to do this in bulk via script

please, anyone, provide help

1 ACCEPTED SOLUTION

BharathChintala
Mega Sage

@rishabh31 

 

You can write this as fix script

BharathChintala_0-1678868521364.png

var gr = new GlideRecord("sc_request");
gr.addQuery("state", "1");
gr.query();
while (gr.next()) {
    gr.state = 4;
    gr.update();
    var gr1 = new GlideRecord("sc_req_item");
	gr1.addQuery('request',gr.sys_id);
    gr1.addQuery("state", "1");
    gr1.query();
    while (gr1.next()) {
        gr1.state = 4;
        gr1.update();
    }
    var gr2 = new GlideRecord("sc_task");
	gr2.addQuery('request',gr.sys_id);
    gr2.addQuery("state", "1");
    gr2.query();
    if (gr2.next()) {
        gr2.state = 4;
        gr2.update();
    }
}

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

You can use the GlideRecord API.  Set your query using addQuery() and perform the update using updateMultiple().

Here's a great article on it:
Pro Tip: Use updateMultiple() for Maximum Efficiency!

BharathChintala
Mega Sage

@rishabh31 

 

You can write this as fix script

BharathChintala_0-1678868521364.png

var gr = new GlideRecord("sc_request");
gr.addQuery("state", "1");
gr.query();
while (gr.next()) {
    gr.state = 4;
    gr.update();
    var gr1 = new GlideRecord("sc_req_item");
	gr1.addQuery('request',gr.sys_id);
    gr1.addQuery("state", "1");
    gr1.query();
    while (gr1.next()) {
        gr1.state = 4;
        gr1.update();
    }
    var gr2 = new GlideRecord("sc_task");
	gr2.addQuery('request',gr.sys_id);
    gr2.addQuery("state", "1");
    gr2.query();
    if (gr2.next()) {
        gr2.state = 4;
        gr2.update();
    }
}

 

 

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala