web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Fetch related entities on delete operation

(0) ShareShare
ReportReport
Posted on by 144

Hi,

I need to fetch related entity records of contact in a plugin on DELETE operation.

Contact and its related entities are having 1:N relationship of Parental behaviour.

Is there any way to fetch related records on delete event without changing the relationship behaviour.

TIA.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    You have to write a plugin on "Pre-Operation" Message of "Delete" Action.

    take the current record id and create queryattribute/queryexpression to retrieve all records where parent record is == current record id.

    here are some examples :  community.dynamics.com/.../245874

    www.inogic.com/.../retrieve-related-entity-records-along-wih-the-primary-entity-using-retrieve-method  

  • snehaln676 Profile Picture
    144 on at

    Hi Rawish,

    Thank you.

    I have already tried with pre-operation plugin on Delete to retrieve related records, but its not working. Retreived records count is appearing as 0.

  • Verified answer
    Rawish Kumar Profile Picture
    13,758 on at

    looks like this issue : community.dynamics.com/.../crm-plugins-retrieve-children-during-delete

    see this and let me if changing this works.

  • Suggested answer
    snehaln676 Profile Picture
    144 on at

    Yes it works! But as pre-validation does not store any transaction, need to get values in shared variables and can use it in pre/post operation to achieve functionality.

    Thank you!

  • AnthonyD Profile Picture
    40 on at

    Hello,

    I have the same issue but in my case it's a N:N relation. When deleting the parent record i want to retrieve the related records for some calculations. I have the delete operation and have it on Pre-Validation.

    However when I run this code which usually works I retrieve 0 entities.

    var query = new QueryExpression()
                    {
                        //Set this to the entity you wish to retrieve data from
                        EntityName = "cref8_cursist",
    
                        //This will return us all columns for each record returned
                        ColumnSet = new ColumnSet(true),
                    };
    
                    //AddLink(RELATIONSHIP ENTITY NAME, ENTITY UNIQUE ID FROM THE ENTITIE YOU WISH TO RETRIEVE DATA FROM, ENTITY UNIQUE ID FROM THE ENTITIE YOU WISH TO RETRIEVE DATA FROM
                    var link = query.AddLink("cref8_extrakost_cref8_cursist", "cref8_cursistid", "cref8_cursistid");
                    link.LinkCriteria = new FilterExpression()
                    {
                        //Add this to filter the Trainee records for a specified Course
                        Conditions =
                                        {
                                            new ConditionExpression("cref8_extrakostid", ConditionOperator.Equal, extraKostEntity.Id)
                                        }
                    };
    
                    //Invoke the service with our query
                    var Cursists = service.RetrieveMultiple(query);

    How did you fix this?

    Best Regards,

    Anthony

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans