- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 02:14 AM
Create a Business Rule which will trigger when record is deleted in Incident table then delete a record in Customer Incident table for that incident.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 03:15 AM
Hi,
Please use before delete business rule and update your logic as this
(function executeRule(current, previous) {
var gr = new GlideRecord('u_customer_incidents'); // give your correct table name
gr.addQuery('u_parent_inc', current.number);
gr.query();
if (gr.next()) {
gr.deleteRecord();
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2022 10:36 AM
Hi
If possible, please provide:
- Table Name: for Customer Incident (until you provide details, let's say: u_customer_incident)
- Reference Record: until you provide details
- On Incident Record that can be used to uniquely identify the relation (let's say: u_customer_incident) OR
- On Customer Incident Record that can be used to uniquely identify the relation (let's say: u_parent_incident)
- Business Rule:
- Table: Incident
- When: Before
- Delete: True
- Advanced: True
- Condition: Customer Incident â–º is NOT Empty
- Script:
Using Point#2.1
(function executeRule(current, previous /*null when async*/) { var customerIncident = current.u_customer_incident.getRefRecord(); if(customerIncident) { customerIncident.deleteRecord(); } })(current, previous);
Using Point#2.2
(function executeRule(current, previous /*null when async*/ ) { var customerIncidentGr = new GlideRecord('u_customer_incident'); customerIncidentGr.addEncodedQuery('u_parent_incident=' + current.getValue('sys_id')); customerIncidentGr.query(); //While loop in case multiple record are to be deleted //If loop in case first appearing record has to be deleted while (customerIncidentGr.next()) { customerIncident.deleteRecord(); } })(current, previous);
Please try and let me know if this works for you.
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2022 09:31 PM
Hi
Did you get a chance to check whether my solution worked for you or not?
If yes and if my answer helped you out then please mark my answer as correct/helpful, so that other community members facing similar issues might get help.
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 06:48 AM
If you don't see the option Delete, you need to check the 'Advanced' checkbox.