to delete records from a table

rachana pant
Tera Contributor

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?

3 REPLIES 3

Ct111
Tera Sage

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.

Not applicable

Hi,

From the Tables and Columns module, complete the following steps.

  1. Navigate to System Definition > Tables and Columns.
  2. Select the table for which to delete records.
  3. Click Delete All Records .
  4. In confirmation box, Enter delete and click 

Mark if helpful

Thankyou

Regards,

Ajay

find_real_file.png

www.dxsherpa.com

 

Not applicable

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

find_real_file.png

www.dxsherpa.com