Best Practice on Script to Delete Records from Instance

richelle_pivec
Mega Guru

If I am running a script to delete several thousand records from a table in Dev (or Test) is it okay to run the same script on a different table at the same time? Slowing down the instances performances isn't really a big issue in this particular case as Dev is only used by me and Test isn't being actively used today.

I'm just wondering if it will cause some other problem or if it is just a really bad practice to run two scripts to delete records at the same time.

thanks,

Richelle

1 ACCEPTED SOLUTION

Dennis R
Tera Guru

You shouldn't have any problems unless the tables have some kind of dependency on each other (such as a reference field from one to the other), which in theory could (but in practice, shouldn't) cause a race condition.

 

It might be worth noting though that if you're running the scripts from the same session, such as logging in and running them as background scripts or fix scripts, I believe that ServiceNow serializes everything in a session so that they won't actually run at the same time. If you log into two different sessions (such as from two different browsers, or in one browser normally and in an "in cognito" window), you can run them simultaneously. Also if you run them as background processes from a fix script they should run simultaneously. Otherwise running one in one session will cause your UI--even across tabs--to not respond until one script finishes.

 

Hope this helps,

--Dennis R

View solution in original post

4 REPLIES 4

Dennis R
Tera Guru

You shouldn't have any problems unless the tables have some kind of dependency on each other (such as a reference field from one to the other), which in theory could (but in practice, shouldn't) cause a race condition.

 

It might be worth noting though that if you're running the scripts from the same session, such as logging in and running them as background scripts or fix scripts, I believe that ServiceNow serializes everything in a session so that they won't actually run at the same time. If you log into two different sessions (such as from two different browsers, or in one browser normally and in an "in cognito" window), you can run them simultaneously. Also if you run them as background processes from a fix script they should run simultaneously. Otherwise running one in one session will cause your UI--even across tabs--to not respond until one script finishes.

 

Hope this helps,

--Dennis R

Both of the tables are extended off of the Task table, so I wonder if there would be problems? But they don't share any dependencies.

I'll give it a try using your idea of using a different browser to initiate the second run of the script. It is a "Scheduled Script Execution" Scheduled Job that I am using "Execute Now" for.

Thanks,

Richelle

It worked. It is deleting records from both tables. I executed the job in separate browsers swapping the table and record count in the script as needed.

Thanks again,

Richelle

Glad I could help. 🙂 It shouldn't have any trouble running against tables extended from Task, but it is a good point that in the ServiceNow back-end, extended tables are actually all contained within the same table as their parent table. It still shouldn't cause an issue though, because by accessing two different extended tables, you're guaranteeing that you won't be accessing the same physical record in the back-end database.

 

If you're running these scripts from scheduled jobs, those should all run in separate sessions and not interfere with each other.