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

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,



Try below;



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();


}



Thank you,


Ashutosh


SNOW User8
Giga Guru

Hi alaganuru krishna reddy




Try 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();


}


Mrudula6
Mega Guru

Hi Krishna,



In your code the "IF" statement has wrong syntax.



Try below code :



var gr = new GlideRecord('change_request');


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


gr.query();


if(gr.next())


{


if(gr.state=='1')


{


gr.state='3';    


gr.u_sub_status ='cancelled';                                                                    


gr.update();


}


}


ram536
Kilo Guru

All these scripts are not working as expected, can we change directly to Closed state from No matter what state it be?