delete records based on condition

venishawakodika
Giga Contributor

Hi All,

I have created 2 tables, say A & B

Table A stores 'project_code;

Table B refers to this project_code & stores other values related to it like project amount & other values.

My requirement is when i delete that project code record from table A, its corresponding entries in table B should get deleted.

I am writing a 'before-delete' BR on table A(after delete does not fetch project code), it doesn't work.

Here is the code:

(function executeRule(current, previous /*null when async*/) {

  // Add your code here

  var bill = new GlideRecord("u_project_billing");

  gs.log('test'+current.u_project_code);

  bill.query();

  while (bill.next()) {

  if(bill.get('u_project_code',current.u_project_code))  

  {

  //bill.deleteMultiple();

  bill.deleteRecord();

  gs.log('test done');

  }

  }

})(current, previous);

Any help on this please.

1 ACCEPTED SOLUTION

I successfully tested this with the following assumptions:


1. This BR runs on table A, while the to-be-deleted records are on B


2. u_project_code is a reference field on Table B - to Table A



      var bill = new GlideRecord("u_project_billing");


      bill.addQuery('u_project_code', current.sys_id);


      bill.deleteMultiple();



I also suggest to add to your Delete UI action an alert about the deletion of related records.



harel


View solution in original post

11 REPLIES 11

The you probably need QuickForms:


GlideDialogWindow: QuickForms - ServiceNow Guru - scroll down a bit and get to where it says "Displaying a form popup from a list (multiple updates with one action)"


Hi,



Iam already there at the stage of creating a dialog window. From the window i want to select multiple items and populate the selected records back to the original form.



Regards


Ganapati