Why can I not use the method "new GlideArchiveRecord().archive(current);" in a fix script?

alecwelle1
Kilo Contributor

I am trying to archive all of our incidents and the archive rules will not allow me to do so because we had to restore all of them because we forgot a crucial step in our archiving process.  I was able to restore all of the records through a script, but am unable to rearchive them through a script after we have filled in a field for all of them.  Why does this method not work or the archive rule not work?

1 ACCEPTED SOLUTION

Sample script : This will query all incident records. You can   filter the records by using addQuery() as per your req


var gr = new GlideRecord('incident');


gr.query();


while(gr.next())


{


new GlideArchiveRecord().archive(gr);


}





Note: Untested


View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Alec,



You need to pass the glideRecord object instead of current when doing it via Fix script


Sample script : This will query all incident records. You can   filter the records by using addQuery() as per your req


var gr = new GlideRecord('incident');


gr.query();


while(gr.next())


{


new GlideArchiveRecord().archive(gr);


}





Note: Untested


shivanipatel
ServiceNow Employee
ServiceNow Employee

Alec,



We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.



If you feel that your question was answered, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This allows other customers to learn from your thread and improves the ServiceNow Community experience.



If you are viewing this from the Community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thanks,


Shivani Patel


Unknown-1.png