Deleting a child record GlideRecord

reginabautista
Kilo Sage

Hi everyone, I'm quite new in ServiceNow so still learning.

I have a Business Rule that deletes child records from a parent table. I have added the code below but for some reason it wouldn't delete the entries. I'm probably missing something here..Any ideas?

  var gr = new GlideRecord('table name');

  gr.addQuery('u_parent', current.sys_id);

  while (gr.next()) {

  gr.deleteRecord();

  }

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

You are missing gr.query() here. Use this script and you are good to go



var gr = new GlideRecord('table name');


  gr.addQuery('u_parent', current.sys_id);


  gr.query();


  while (gr.next()) {


  gr.deleteRecord();


  }



You can also use this to delete multiple records


var gr = new GlideRecord('table name');


  gr.addQuery('u_parent', current.sys_id);


  gr.deleteMultiple();


View solution in original post

6 REPLIES 6

Ow! missed that! My points!


Abhinay Erra
Giga Sage

Glad you got your question answered.