First, you'll need to clear the relationship(s) by using .clear() or .remove(), whichever suits your needs better.
After that, you'll need to delete the object(s) by using the [YourModel].delete() method.
10-22-2018 09:23 PM
Hi,
I want to Remove already created M2M Relationship for the Tables and again i have to create the M2M relationship with New Tables by using Business Rules.
If any one can Explain?
By,
Meena
10-22-2018 11:47 PM
Create a business rule on the required table
When to run condition should be :Status Changes to XYZ //Put the required status
Script :
var gr = new GlideRecord("sys_relationship");
gr.addQuery("name", "Give the relationship name");
gr.query();
if (gr.next()) {
gr.deleteRecord();
gr.update();
}
The above Script will delete the Relationship from the table when status changed.
First try it in your personal Dev instance and see. If that is what your requirement is, then implement the same in your required instance.
10-23-2018 12:27 AM
Thanks Ravi....
But it's not working...
Do you have Some other Idea?
02-26-2023 06:24 AM
10-22-2018 11:34 PM
Any one Know how to Remove the M2M relation by Using Business rules. Because i have to remove the M2M Relation based on the Status Change.....
10-23-2018 12:00 AM
First, you'll need to clear the relationship(s) by using .clear() or .remove(), whichever suits your needs better.
After that, you'll need to delete the object(s) by using the [YourModel].delete() method.
.remove()
will delete the relationship usingQuerySet.delete()
. This should delete the related object I supposeNOTE: Mark correct or helpful if it helps you.
Warm Regards,
Raj patel