How to write a fix script to delete multiple records from a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2021 06:20 AM
Hi I need to run a fix script to delete multiple records from a custom table if the class is Windows server and created by is me.
Initially to check it I wrote the below fix script(to see the exact count of the records in the logs-couldnt see that as well), which isnt working, Can anyone help me on it.
var gr = new GlideRecord('u_ci_loader_for_servers');
gr.addQuery("u_class="+cmdb_ci_win_server);
gr.query();
while(gr.next()){
// gr.deleteMultiple();
// gr.update();
gs.info(gr.getRowCount() + "Test");
}
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 07:03 AM
Hi,
Indeed it does 🙂
Glad it helped you.
If the author returns here, seeing as this is from over a year ago, if you could mark my reply above as Correct, so that others can find it faster and easier, that'd be great.
Take care!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2021 06:25 AM
Hi Try below one
var gr = new GlideRecord('u_ci_loader_for_servers');
gr.addEncodedQuery("opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^u_class="+cmdb_ci_win_server);
gr.query();
gr.deleteMultiple();
Please mark my answer correct/helpful if applicable.
Thank you
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2021 06:34 AM
Sample script is already shared by Anirudh
Just adding to his point.
1) wrap the code inside function
2) give correct user id here
deleteRecords();
function deleteRecords(){
var gr = new GlideRecord('u_ci_loader_for_servers');
gr.addEncodedQuery("u_class="+cmdb_ci_win_server);
gr.addQuery("sys_created_by" , 'yourUserIdHere'); // give the user id here
gr.query();
gr.deleteMultiple();
}
Regards
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-05-2021 10:41 PM
Hope you are doing good.
Would you mind marking the best matching answer as correct and helpful, to close this thread?
Regards
Ankur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-08-2021 03:17 AM
Hope you are doing good.
Would you mind marking the best matching answer as correct and helpful, to close this thread?
Regards
Ankur