I wanted to delete related records in other table

now_dev
Mega Expert

Hi All,

I have two tables. 1) For Services which is nothing but a list of services. 2) Appointmnets for services.

When I delete any service from first table I like to delete related records from the other tables. Any suggestion

6 REPLIES 6

Yes, your understanding is correct. By alert I mean some info to Admin that they cannot delete the service as few appointmnet exist for this services.


Admin should not be able to delete.


Write a delete before business rule on that service table with the following script:



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




  var gr = new GlideRecord('<appointment table name>');


  gr.addQuery('<field_name>', current.sys_id); // field name of appointment table which stores the service value


  gr.query();



  if (gr.next())


  {


  gs.addErrorMessage('You can not delete as Appointment is using this');


  current.setAbortAction(true);


  }


})(current, previous);




Make sure you provide correct table and field name in order to run this business rule properly.