to delete records from a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2018 11:21 PM
i want to delete records from my table(example - final table).
Please let me know-
1. what script should i write?
2.where i will will write this script
in business rule or somewhere else?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2018 11:26 PM
Hi ggjk
Execute the below script in scripts background if you want to delete as per the number (sequence)
var incrd = new GlideRecord('incident');
incrd.orderBy('number');
incrd.query();
if(incrd.next())
{
gs.info('Record deleted was '+incrd.number); // This query was deleting first record since sorting with number was done.
incrd.deleteRecord();
}
or
Take the below example and try
var rec = new GlideRecord('incident');
rec.addQuery('active',false);
rec.query();
while (rec.next()) {
gs.print('Inactive incident ' + rec.number + ' deleted');
rec.deleteRecord();
}
PLEASE mark my answer as correct if it served your purpose.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2018 11:29 PM
Hi,
From the Tables and Columns module, complete the following steps.
- Navigate to System Definition > Tables and Columns.
- Select the table for which to delete records.
- Click Delete All Records .
- In confirmation box, Enter delete and click
Mark if helpful
Thankyou
Regards,
Ajay
www.dxsherpa.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2018 11:32 PM
And you can also do it through "Script-Background" by writing below code :
var gr= new GlideRecord("your_table_name");
gr.query();
gr.setWorkflow(false); //Don't fire Business rule,notifications
gr.deleteMultiple();
}
Regards,
Ajay
www.dxsherpa.com