need to change the change request status from implementation approval to Closed

ram536
Kilo Guru

Hello Am using the below script to change the Change request status from implementation approval(1) to Closed(3) and sub status(cancelled ) to but its not working for me, can you suggest something.

var gr = new GlideRecord('change_request');

gr.addQuery('number', 'CHG0054828');

gr.query();

while(gr.next())

{

If (gr.state=='1');

gr.state='3';      

gr.u_sub_status = 'cancelled';                                                                    

gr.update();

}

1 ACCEPTED SOLUTION

Hello Mrudula,



Am running the script on Script back ground, i need the given change number to be closed cancelled irrespective of any stage.


find_real_file.png


View solution in original post

9 REPLIES 9

It should work,



Go to   System Definition -> Fix Script & execute this one



var gr = new GlideRecord('change_request');


gr.addQuery('number', 'CHG0054828');


gr.query();


while(gr.next())


{


if(gr.state == 1);


gr.state = 3;  


gr.u_sub_status = 'cancelled';   //put correct value                                                  


gr.update();


}




If you want to close all Change Request regardless of states then write Onload client script on Change Request table.


Could you give us a little bit more background on where have you implemented this code script? Is it a UI action, workflow or BR etc?


Hello Mrudula,



Am running the script on Script back ground, i need the given change number to be closed cancelled irrespective of any stage.


find_real_file.png


Hi,



gr.state = '3'; Should be replaced with gr.state = 3;



Thank you,
Ashutosh Munot




Please close this thread if you got your answer by marking answer Correct or Helpful


Hi ,



I ran the below script and it executed as expected in my instance. Is your script executing till the end? Try gs.print statement to check until which point does it run. If it still does not update, check for some Business rule which might be aborting the update.



var gr = new GlideRecord("change_request");


gr.addQuery('number','CHG0040007');


gr.query();


if(gr.next())


{


gs.print("Number is "+gr.number);


gs.print("state now is "+gr.state);


gr.state = 5; // In my instance 5 value is assigned to "In progress" state


gr.update();


gs.print("state now is "+gr.state);


}