Monday, January 30, 2012

Dealing with N:N Relationship in MS CRM - 2011

In the latest version of MS CRM 2011, the AssociateEntitiesRequest class has been deprecated. Now, we need to make use of AssociateRequest Class.

Here is an example to associate an entity record.

// Create the request object and set the monikers with the
// orderproduct_association relationship.
AssociateRequest productOrder = new AssociateRequest
{
    Target = new EntityReference(order.EntityLogicalName, orderId),
    RelatedEntities = new EntityReferenceCollection
    {
        new EntityReference(product.EntityLogicalName, productId)
    },
    Relationship = new Relationship("orderproduct_association")
};

// Execute the request.
_serviceProxy.Execute(productOrder);

3 comments:

Peter H said...

Absolutley brilliant - thank you thank you

Anonymous said...

Very simple to do this from plugin than from JavaScript. Thank you for the code.

Richard C. Lambert said...

McKinney TX Feb 26 2010 A McKinney high school teacher was arrested Wednesday on a charge of an improper relationship with a student, a second-degree felony, police said. gana hakim