locked
Plugins RRS feed

  • Question

  • Hi, I'm new in writing plugins. Please help me to do the following thing:

    I have a custom "Loan details" entity connected with an "Opportunity" entity via N:N relationship. In opportunity record I have some "connection" connections, e.g. with a "seller" connection role. I want to pass all "seller connections" from opportunity to "Loan details" record.  Please help me to solve this problem.  Thanks in advance.

    Sunday, March 1, 2015 4:52 PM

Answers

  • Hi,

    You can use associate message. 


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog

    • Marked as answer by gMary Tuesday, April 21, 2015 5:55 PM
    Sunday, March 1, 2015 6:03 PM
  • You can use RetrieveMultiple to get the data from the related entities. If the records are related via a Connection, then the RetrieveMultiple should be on the connection entity, with a filter on record1id to match the opportunity. Note that, for connections, you can filter either on record1id or record2id, as they are interchangeable

    If the records are related via a N:N relationship, then the RetrieveMultiple should be on the entity that forms the N:N relationship - this is the same as the relationship name


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by gMary Tuesday, April 21, 2015 5:55 PM
    Monday, March 2, 2015 2:27 PM
    Moderator
  • Hi gMary,

    Below is the code to retrive the related records:

                ConditionExpression condition_connectionShouldBeOfNeededOpportunity = new ConditionExpression();
                condition_connectionShouldBeOfNeededOpportunity.AttributeName = "record1id";
                condition_connectionShouldBeOfNeededOpportunity.Operator = ConditionOperator.Equal;
                condition_connectionShouldBeOfNeededOpportunity.Values.Add(new Guid("opportunity guid"));
                ConditionExpression condition_ConnectionShouldBeForSellerRole = new ConditionExpression();
                condition_ConnectionShouldBeForSellerRole.AttributeName = "record1roleid";
                condition_ConnectionShouldBeForSellerRole.Operator = ConditionOperator.Equal;
                condition_ConnectionShouldBeForSellerRole.Values.Add("'seller' connection role guid");
                QueryExpression query1 = new QueryExpression();
                query1.ColumnSet = new ColumnSet(true);
                query1.EntityName = "connection";
                query1.Criteria.AddCondition(condition_connectionShouldBeOfNeededOpportunity);
                query1.Criteria.AddCondition(condition_ConnectionShouldBeForSellerRole);
                EntityCollection result = iOrganizationService.RetrieveMultiple(query1);

    It will retrieve only those connection which having your need opportunity with the "Seller Role".

                foreach (var item in result.Entities)
                {
                    //associate item to "Loan Details"
                }

    this will associate "seller connections" from opportunity to "Loan details" record.


    • Edited by Piyush Parate Monday, March 2, 2015 3:27 PM
    • Proposed as answer by Piyush Parate Monday, March 2, 2015 3:27 PM
    • Marked as answer by gMary Tuesday, April 21, 2015 5:55 PM
    Monday, March 2, 2015 3:22 PM

All replies

  • Hi,

    You can use associate message. 


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog

    • Marked as answer by gMary Tuesday, April 21, 2015 5:55 PM
    Sunday, March 1, 2015 6:03 PM
  • Ok, but I suppose in my code I need to get all seller connections connected with an opportunity and create new seller connections in this case connected with "loan diteils" card via associate message.

    as I never before write a plugin I don't know how to get datas from related entities. Can you help me?

    Monday, March 2, 2015 11:32 AM
  • You can use RetrieveMultiple to get the data from the related entities. If the records are related via a Connection, then the RetrieveMultiple should be on the connection entity, with a filter on record1id to match the opportunity. Note that, for connections, you can filter either on record1id or record2id, as they are interchangeable

    If the records are related via a N:N relationship, then the RetrieveMultiple should be on the entity that forms the N:N relationship - this is the same as the relationship name


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by gMary Tuesday, April 21, 2015 5:55 PM
    Monday, March 2, 2015 2:27 PM
    Moderator
  • Hi gMary,

    Below is the code to retrive the related records:

                ConditionExpression condition_connectionShouldBeOfNeededOpportunity = new ConditionExpression();
                condition_connectionShouldBeOfNeededOpportunity.AttributeName = "record1id";
                condition_connectionShouldBeOfNeededOpportunity.Operator = ConditionOperator.Equal;
                condition_connectionShouldBeOfNeededOpportunity.Values.Add(new Guid("opportunity guid"));
                ConditionExpression condition_ConnectionShouldBeForSellerRole = new ConditionExpression();
                condition_ConnectionShouldBeForSellerRole.AttributeName = "record1roleid";
                condition_ConnectionShouldBeForSellerRole.Operator = ConditionOperator.Equal;
                condition_ConnectionShouldBeForSellerRole.Values.Add("'seller' connection role guid");
                QueryExpression query1 = new QueryExpression();
                query1.ColumnSet = new ColumnSet(true);
                query1.EntityName = "connection";
                query1.Criteria.AddCondition(condition_connectionShouldBeOfNeededOpportunity);
                query1.Criteria.AddCondition(condition_ConnectionShouldBeForSellerRole);
                EntityCollection result = iOrganizationService.RetrieveMultiple(query1);

    It will retrieve only those connection which having your need opportunity with the "Seller Role".

                foreach (var item in result.Entities)
                {
                    //associate item to "Loan Details"
                }

    this will associate "seller connections" from opportunity to "Loan details" record.


    • Edited by Piyush Parate Monday, March 2, 2015 3:27 PM
    • Proposed as answer by Piyush Parate Monday, March 2, 2015 3:27 PM
    • Marked as answer by gMary Tuesday, April 21, 2015 5:55 PM
    Monday, March 2, 2015 3:22 PM
  • Thanks for your reply. One more question: In this case my plugin will be triggered every time any kind of 2 (or more) entities get associated by any native N:N relationship (so it will trigger for all N:N connected entities? ).

    Thursday, March 19, 2015 1:54 PM