The CreatorCon Call for Content is officially open! Get started here.

my incident tickets: when ever we will "cancelled" the Incident ticket "active is false "by default But I am facing the cancelled Incidents also active is true.so can any one provide the code for cancelled tickets i have to set false .

padhu1
Kilo Expert

Hi friends,

my incident tickets: when ever we will "cancelled" the Incident ticket "active is false "by default   But I am facing the cancelled Incidents also active is true.so can any one provide the code for cancelled tickets i have to set active is   false .

is it clear?if not please comment the same.

Thanks in Advance.

13 REPLIES 13

vinothkumar
Tera Guru

Hi Padhu,



Create a one time schedule job to make all the cancelled incident as inactive and also modify your UI action cancel script to make the record inactive.



As mentioned in the earlier comment, you should have to update your business rules to include the cancelled state to make your record inactive



var gr = new GlideRecord('incident');


      gr.addQuery('state', 'Cancelled'); //Cancelled state Value


     


      gr.query();


      while(gr.next()) {


          gr.state = 'cancelled';


         


          gr.active = false;


          gr.update();


    }



Please mark as helpful if it   answer your query


Hi Vinoth,


                                                                    This business Rule will change the existing Cancelled INC's(around 900) active is true to active is false(this script is not making the existing Cancelled INC's(around 900) active is true to active is false).i checked please respond the same.see the below screen short for cancelled incidents active is true.


find_real_file.png



Thanks in advance.


Hi Padhu,



Run a background script in batches if its in production , if not run a background script for all the 900 cancelled inc's whose statuses needs to be changed but be careful as it will impact instance performance or it will hang .So, its better to set a limit of 50 -100 while retrieving records,so it doesnt hang your instance.




var gr   = new GlideRecord('incident');


gr.addQuery('state','cancelled');     // check here the name of the column and its values


gr.addQuery('active',true);


gr.setLimit(100);   // optional


gr.query();



while(gr.next())


{


gr.active = false;


gr.update();


}



To automate the same


write a on before/update BR



condition field   : current.state.changesTo('cancelled') || current.state.changesTo('resolved')



script field :    


current.active = false;



Hope this helps .


HI Sujala thanks for the quick response,



                                                yes i am facing issue in production only. Here bit confusing background script in batches(what it mean exactly batches)? and you mentioned 2 scripts here which one i have to use 1 or 2?


1.var gr   = new GlideRecord('incident');


gr.addQuery('state','cancelled');     // check here the name of the column and its values


gr.addQuery('active',true);


gr.setLimit(100);   // optional


gr.query();



while(gr.next())


{


gr.active = false;


gr.update();


}



(or)


2.condition field   : current.state.changesTo('cancelled') || current.state.changesTo('resolved')


script field :


current.active = false;


I am pasting the screen short here.


find_real_file.png


sujalavemula
Kilo Guru

to inactivate existing cancelled and resolved incidents



step 1 : if you are a security admin ,elevate privilage , else give yourself security_admin role ,logout and login again.


step 2 : elevate privilages.


step 3 : go to application pane on left side and search for background script


step 4 : click on it


just past the below content and run it.




var gr   = new GlideRecord('incident');


gr.addQuery('state','cancelled');     // check here the name of the column and its values


gr.addQuery('active',true);


gr.setLimit(100);   // optional


gr.query();



while(gr.next())


{


gr.active = false;


gr.update();


}







Second part :




To automate above functionality , meaning if you want incidents in active status to be changed to false as soon as the users change inc state to cancelled or resolved .



Write on before - update   business rule



condition field   :


current.state.changesTo('cancelled') || current.state.changesTo('resolved')


script field :


current.active = false;