logo

NJP

Archive and Destroy Rules in ServiceNow

Import · Dec 21, 2023 · video

[Music] hey everyone it's Justin thank you for watching and welcome to my house did you know that you can set up archiving and Destroy rules in your service now instance that's what I want to talk about in this video come with me I've got a table that I just created recently check out my other video I'll link to it up above for application fingerprinting or hashing and fingerprinting to do quick comparisons I have a table called application crawl history this is part of my application that crawls the service now store pulls back into the update so I can make my Friday SSH episodes but I quickly I think quickly I'm going to run out of room or I'm going to use up too much space on this table so it's a good candidate for setting up an archive rule in my personal developer instance or my PDI now I've never set up an archive rule I just read about it and I'm going to do it with you watching and for the first time so we can see how all this works so what I understand most of the archiving stuff lives under this menu item system archiving and you can see there I've got archive rules archive log uh archive destroy rules archive destroy log archive status and then some archive properties and tables now I'm just going to focus on the rules and if we have time here I'm going to do a destroy rule but let's go ahead and go to Archive rules again I'm in my PDI and you see there's already some stuff set up from out of the boox applications that's doing some archiving so number one I didn't even know that existed um but I want to create my own I'm not going to mess with anything out of the box so I'm going to use this new button here and I'm going to point it to that application call histories table now one thing I noticed because of the nice little helpful Banner on this form is that it only it's application scope Pacific application scope specific in order to do the archiving so you could get into some gnarly situations where you've got data stretching across applications if that's the case this video is not for you I'm going to try to keep it simple and do a basic archive rule so let's just call this application crawl histories and I want to say uh greater than 30 days old so that's about all I need for my purposes if I can just see a few crawls that's 30 days would be four crawls you know I do a crawl a week four to five crawls so we're going to use the application crawl history table I might do this for another table probably the version history sometime in the future but right now just going to focus on this application crawl history because I did not want it to get crazy out of whack um I'm not worried about retaining references in this because again I don't see me using this data but I do need to add a condition so we're going to say uh created and then I'm going to do relative to uh let's say before 30 days ago so we'll do days 30 days ago so I want to look for anything created before uh 30 days ago and let's go ahead and I'm not going to worry about I'm not going to restore anything um that's where you'd set up this autoarchive option um but I'm not probably not going to restore anything so that's it I'm going to hit save again I've never done this before uh record estimate recal record estimate recalculated it sees 2520 three records that would be affected by this and um let's see archive related records archive run how do I run this thing interesting um is it just happen automatically automatically let's see uh restore archived records let's say create a destroy rule create an archive rule is what I just did and we did that we did all that stuff submit calculate the estimated number what to do next after verifying that the archive rule is selecting records as expected activate the archive rule if you not want to wait for the schedule job to run the archive rule you can manually start the Run archive archive rule by clicking run archive now okay so there must be ah I missed an active button here um that showed up when I saved the form so let's go ahead and check the active button and we'll save it again and it sounds like now I have a run archive Now button perfect so I'm going to go ahead and let's go look at the table real quick before I run the archives we'll go to application crawl histories we I've got 10,070 records so let's go back to my archive Rule and we're going to go ahead and run the archive now running archive rule application crawl history is greater than 30 days old um so let's I'm just going to start refreshing here and see what happens now while we're waiting on that what is supposed to happen is it's supposed to create an archive table so a table named arcore and then the table name my table name is xcore 417 399 underscore store blah blah blah blah blah so um there should be an archive table at some point during this process interesting I don't see anything yet let's go back to the archive Rule and O archive Run State 32 seconds it started three batches of 190 that's interesting archive run let's go ahead and open one of these up I'm just curious I've never seen how this works created from table to table okay there's that AR underscore that I was just telling you about and it has an ID this is very interesting oh we're up to 333 I'm just going to refresh [Music] there so those are still oh 400 okay this number is climbing um as it started it's it's interesting there's three of them I didn't hit three but um yeah we'll just let it do its thing and archive map crawl history is greater than 30 days old not see anything there let's go to the table now go back to the table application crawl history okay it's shrinking yep look at that so it was 10,070 now we're down to 8,881 so let's actually working it's archiving my data um next run date will be today at 11: Pacific these are okay one's completed and two more are active so this must be like a threaded process right like it sends out cuz that one completed after 523 but the other two are still cranking we're almost at 2,000 in aggregate there all right so I feel good about this that one just completed 1,000 oh must be 1,000 is the yeah so 2523 so it uh it threads a th000 interesting uh cap so I just learned something um so there's nothing left to Archive that'll run on the schedule jobs so I don't have to maintain it or anything I'm going to go ahead and refresh this form uh archive related records so I'm not seeing the actual records that got created uh let's go to I'm going to refresh my page so that my menu refreshes my all menu here cuz I'm wondering if in the archive tables there'll be a link to my archived application crawl histories wait for this to load there we go system archiving and there it is archive application crawl history is now my table showing up in my menu item so I didn't have to do that it just showed up there and then here is the 2523 archived records and if I click on one I should see the release notes the application details okay so everything's intact and uh looks like exactly like I need it I can restore the record and related records or I can show the archive log entry so I'm good um this is looking good now I've got a table that's going to maintain itself last thing I want to do is set up a destroy rule I want to destroy the archive data after I said I did 30 days so after 90 days that data can go I really don't care at that point so we'll call this destroy application crawl history archives and the table is going to be oh I have three tables for application archive application crawl history that's not what I wanted I want three tables interesting um so amount of time records will stay in the archive before they're destroyed so we'll say 90 days so that'll be a total life of 120 days okay so let's say 60 days that'll be a total life of 90 days right so it's 30 days to come off the regular table 60 days to get destroyed from the archive table and uh we'll and save that just like we did the other one and there's probably not going to be a record estimate because I don't have anything that's that old uh so let's just recalculate estimate yeah zero so nothing there um but I'm going to go ahead and activate it and that way when that does happen that archive should stay up to date so um two things you just saw there one creating an archive rule um lots of stuff happened in the background it created another table and it's moving the stuff over there and kind of storing it in a uh less computationally intense way so it's not indexed like the rest of the tables I think the number and like two other fields are actually indexed and so this is taking up less resources less compute resources so that was the archive Rule and then the destroy rule is to when to get it out of that archive when to take it away so in my use case 30 days on my application crawl histories 60 days in the archive and that sucker is gone I hope you found this video helpful if you did please like Please Subscribe or share it with somebody who you think might be interested in archiving data inside their service now instance and until next time don't forget to always be learning [Music] [Music]

View original source

https://www.youtube.com/watch?v=36CXcv3R5sg