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

tanumoy
Tera Guru

write a delete after business rule on the first table with a script like below:



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


gr.addQuery('field name that contains the service', current.sys_id); //assuming the field is a reference


gr.query();


gr.next();


gr.deleteMultiple();




Replace the table and field names properly. Let me know the result.


tanumoy
Tera Guru

Hi,



Do you need any other assistance on this?


Thanks Tanumoy for quick response. Requirementt got changed. Now I have to check if user has any appointment for services and if Admin try to delete the service, system should display alert. Also I have to display this alert on the list view.


find_real_file.png


So the new requirement is if admin try to delete a record from service table, it will check that if any appointment is there in appointment table with that service. If yes, system will show alert. Is my understanding correct?



Now when you say alert, that means after clicking on Ok it will delete the service record. Right? Or you you want not to delete that?