I wanted to delete related records in other table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2016 06:57 AM
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
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2016 01:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2016 01:45 AM
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.