Need script to delete a record for particular sys_id (xyz) in an incident table?

dyadav
Mega Contributor

Need script to delete a record for specific given sys_id (xyz) in an incident table(for example)?

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Hi,



You can try this code



var gr = new GlideRecord('incident');


gr.addQuery('sys_id', 'your_sys_id');


gr.query();


gr.next();


gr.deleteRecord();



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


View solution in original post

6 REPLIES 6

Alikutty A
Tera Sage

Hi,



You can try this code



var gr = new GlideRecord('incident');


gr.addQuery('sys_id', 'your_sys_id');


gr.query();


gr.next();


gr.deleteRecord();



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


nayanawadhiya1
Kilo Sage

Hey Divya,



find_real_file.png



Refer this -


GlideRecord - ServiceNow Wiki


Shiva Thomas
Kilo Sage

Hi Divya,



Here is an even shorter code snippet:



var gr = new GlideRecord('incident');


gr.get(sys_id_of_record_here);


gr.deleteRecord();



Get() is perfect when you want to retrieve a single record by sys_id.


Thanks Shiva,


Found your method is the shortest among all.