How to Remove M2M Relationship ?

Pandimeena R
Mega Contributor

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

9 REPLIES 9

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.

 

Thanks Ravi....

But it's not working...

Do you have Some other Idea?

How did you deleted that ,still that delete option is hide

Pandimeena R
Mega Contributor

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.....

Raj68
Mega Guru
Hi,

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.

  • for m2m fields .remove() will delete the relationship using QuerySet.delete(). This should delete the related object I suppose
    and then put the condition also whatever condition you want to give.
     

    NOTE: Mark correct or helpful if it helps you.

     

    Warm Regards,

    Raj patel