How to set workflow stage to complete using script

omsa1
Kilo Guru

Hi There,

i've modified the workflow recently which closing workflow by itself. But old requested items still in execution stage.Is there a way to set workflow from executing to complete manually the old requested item which are in complete state.

1 ACCEPTED SOLUTION

preddy
Kilo Guru

Hi Sarasaamani,



Using background Script you can close the workflow stage.



var gr   = new GlideRecord("sc_req_item");


gr.addQuery("stage","executing");


gr.query();


gs.getRowCount("Records:" +gr);


if(gr.next()){


gr.autoSysFields(false);


gr.setWorkflow(false);


gr.stage = "complete";


gr.update();


}



PS: Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

8 REPLIES 8

snehabinani26
Tera Guru

BALAJI40
Mega Sage

Based on your point, you want to set the old request item stage need to complete. Modified workflow will not execute on old request item.


fro that You need write a fix script or background script ,glide record on request item table and query the those old requests and set the stage value to complete.


preddy
Kilo Guru

Hi Sarasaamani,



Using background Script you can close the workflow stage.



var gr   = new GlideRecord("sc_req_item");


gr.addQuery("stage","executing");


gr.query();


gs.getRowCount("Records:" +gr);


if(gr.next()){


gr.autoSysFields(false);


gr.setWorkflow(false);


gr.stage = "complete";


gr.update();


}



PS: Hit like, Helpful or Correct depending on the impact of the response


Hi Pavan,



i tried your script in scheduled job and its not working:(