locked
DisassociateEntitiesRequest remove all at once RRS feed

  • Question

  •  

    Hi,

     

    Is there any way to remove all entities association at once by using DisassociateEntitiesRequest? If no how I can have list of existing associations to remove it one by one?

     

    thank you

     

    this is code which I am trying to use

     

    // Create the condition to test the opportunityid

    CrmSdk.ConditionExpression ce = new CrmSdk.ConditionExpression();

    ce.AttributeName = "new_serialnumber";

    ce.Operator = CrmSdk.ConditionOperator.Equal;

    ce.Values = new object[] { "123456789" };

    // Create the link entity from opportuntiycompetiorsto competitor.

    CrmSdk.LinkEntity le = new CrmSdk.LinkEntity();

    le.LinkFromAttributeName = "productid";

    le.LinkFromEntityName = CrmSdk.EntityName.product.ToString();

    le.LinkToAttributeName = "productid";

    le.LinkToEntityName = CrmSdk.EntityName.new_accountdongle.ToString();

    CrmSdk.LinkEntity le2 = new CrmSdk.LinkEntity();

    le2.LinkFromAttributeName = "new_accountdongleid";

    le2.LinkFromEntityName = CrmSdk.EntityName.new_accountdongle.ToString();

    le2.LinkToAttributeName = "new_accountdongleid";

    le2.LinkToEntityName = CrmSdk.EntityName.product.ToString();

     

    // Add the condition to the link entity.

    le2.LinkCriteria = new CrmSdk.FilterExpression();

    le2.LinkCriteria.Conditions = new CrmSdk.ConditionExpression[] { ce };

    // Create a query expression.

    CrmSdk.QueryExpression qe = new CrmSdk.QueryExpression();

    qe.EntityName = CrmSdk.EntityName.new_accountdongle.ToString();

    qe.ColumnSet = new CrmSdk.AllColumns();

    // Add the from and to links to the query.

    le.LinkEntities = new CrmSdk.LinkEntity[] { le2 };

    qe.LinkEntities = new CrmSdk.LinkEntity[] { le };

    // Retrieve the roles and write each one to the console.

    CrmSdk.RetrieveMultipleRequest retrievequery = new CrmSdk.RetrieveMultipleRequest();

    retrievequery.Query = qe;

    CrmSdk.RetrieveMultipleResponse retrievedProduct = (CrmSdk.RetrieveMultipleResponse)myCrm.Execute(retrievequery);

    for (int i = 0; i <= retrievedProduct.BusinessEntityCollection.BusinessEntities.Length - 1; i++)

    {

    CrmSdk.product retrievedEntity = (CrmSdk.product)retrievedProduct.BusinessEntityCollection.BusinessEntitiesIdea;

    label1.Text = label1.Text + retrievedEntity.name.ToString();

    }

     

     

    Tuesday, November 4, 2008 3:50 AM

Answers

  • Yes, it is very much possible. How are you developing your feature.

     

    I have created an application the associates and disassociates two custom entities. I have created a grid and get all the records of those entities in my windows form applciation. then use loop to disassociate records.

     

    Tuesday, November 4, 2008 8:40 PM
    Moderator
  •  

    I have used following code to fetch many to many entries.

     

                QueryExpression qe = new QueryExpression();

                qe.EntityName = "EntityOne";

                qe.ColumnSet = new AllColumns();           

     

                // Create the link entity

                LinkEntity le = new LinkEntity();

                le.LinkFromEntityName = "EntityOne";

                le.LinkFromAttributeName = "EntityOneid";

                le.LinkToEntityName = "EntityTwo_EntityOne";

                le.LinkToAttributeName = "EntityOneid";

     

                LinkEntity le2 = new LinkEntity();

                le2.LinkFromEntityName = "EntityTwo_EntityOne";

                le2.LinkFromAttributeName = "EntityTwoid";

                le2.LinkToEntityName = "EntityTwo";

                le2.LinkToAttributeName = "EntityTwoid";

                ConditionExpression ce = new ConditionExpression();

                ce.AttributeName = "EntityTwoid";

                ce.Operator = ConditionOperator.Equal;

                ce.Values = new object[] { new Guid(EntityTwoid) };

     

                // Add the condition to the link entity.

                le2.LinkCriteria = new FilterExpression();

                le2.LinkCriteria.Conditions.Add(ce);

     

                // Add the from and to links to the query.

                le.LinkEntities.Add(le2);

                qe.LinkEntities.Add(le);

     

                RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();

                retrieve.ReturnDynamicEntities = true;

                retrieve.Query = qe;

     

                RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);

     

     

    Tuesday, November 4, 2008 9:24 PM
    Moderator
  •  

    This is the intermediate entity created by CRM framework. look at your many to many relationship in relationshipd section of entity customization. it is usualy firstentity_secondentity. just a name concatenation.
    Tuesday, November 4, 2008 9:50 PM
    Moderator
  • seems Ok to me. Try to debug and execute. When working try to add disassociate code in loop.

     

    Tuesday, November 4, 2008 10:16 PM
    Moderator
  • Finally I get it Smile I had issue with that line as well:

     

    qe.EntityName = CrmSdk.EntityName.product.ToString();

     

    Anyway this is whole code which is working and as resault give me name of all products related to dongles.

     

    // Create the condition to test the opportunityid

    CrmSdk.ConditionExpression ce = new CrmSdk.ConditionExpression();

    ce.AttributeName = "new_accountdongleid";

    ce.Operator = CrmSdk.ConditionOperator.Equal;

    ce.Values = new object[] { "5ad4ec4a-93a0-dd11-b92c-00065bfe50f3" };

    // Create the link entity from opportuntiycompetiorsto competitor.

    CrmSdk.LinkEntity le = new CrmSdk.LinkEntity();

    le.LinkFromEntityName = CrmSdk.EntityName.product.ToString();

    le.LinkFromAttributeName = "productid";

    le.LinkToEntityName = "new_new_accountdongle_product";

    le.LinkToAttributeName = "productid";

    CrmSdk.LinkEntity le2 = new CrmSdk.LinkEntity();

    le2.LinkFromEntityName = "new_new_accountdongle_product";

    le2.LinkFromAttributeName = "new_accountdongleid";

    le2.LinkToEntityName = CrmSdk.EntityName.new_accountdongle.ToString();

    le2.LinkToAttributeName = "new_accountdongleid";

     

    // Add the condition to the link entity.

    le2.LinkCriteria = new CrmSdk.FilterExpression();

    le2.LinkCriteria.Conditions = new CrmSdk.ConditionExpression[] { ce };

    // Create a query expression.

    CrmSdk.QueryExpression qe = new CrmSdk.QueryExpression();

    qe.EntityName = CrmSdk.EntityName.product.ToString();

    qe.ColumnSet = new CrmSdk.AllColumns();

    // Add the from and to links to the query.

    le.LinkEntities = new CrmSdk.LinkEntity[] { le2 };

    qe.LinkEntities = new CrmSdk.LinkEntity[] { le };

    // Retrieve the roles and write each one to the console.

    CrmSdk.RetrieveMultipleRequest retrievequery = new CrmSdk.RetrieveMultipleRequest();

    retrievequery.Query = qe;

    CrmSdk.RetrieveMultipleResponse retrievedProduct = (CrmSdk.RetrieveMultipleResponse)myCrm.Execute(retrievequery);

    for (int i = 0; i <= retrievedProduct.BusinessEntityCollection.BusinessEntities.Length - 1; i++)

    {

    CrmSdk.product retrievedEntity = (CrmSdk.product)retrievedProduct.BusinessEntityCollection.BusinessEntitiesIdea;

    label1.Text = label1.Text + retrievedEntity.name.ToString();

    }

     

     

    THANK YOU FOR YOUR HELP

    Tuesday, November 4, 2008 10:27 PM

All replies

  • Yes, it is very much possible. How are you developing your feature.

     

    I have created an application the associates and disassociates two custom entities. I have created a grid and get all the records of those entities in my windows form applciation. then use loop to disassociate records.

     

    Tuesday, November 4, 2008 8:40 PM
    Moderator
  • Hi,

     

    I have one relationship many to many and I am trying to get list of productID which are assign to my custom entity. Then I would like delete them one by one, byt I can not make code above to work. Maybe I am doing somethink wrong. Thank for any help.

     

    Tuesday, November 4, 2008 9:08 PM
  •  

    I have used following code to fetch many to many entries.

     

                QueryExpression qe = new QueryExpression();

                qe.EntityName = "EntityOne";

                qe.ColumnSet = new AllColumns();           

     

                // Create the link entity

                LinkEntity le = new LinkEntity();

                le.LinkFromEntityName = "EntityOne";

                le.LinkFromAttributeName = "EntityOneid";

                le.LinkToEntityName = "EntityTwo_EntityOne";

                le.LinkToAttributeName = "EntityOneid";

     

                LinkEntity le2 = new LinkEntity();

                le2.LinkFromEntityName = "EntityTwo_EntityOne";

                le2.LinkFromAttributeName = "EntityTwoid";

                le2.LinkToEntityName = "EntityTwo";

                le2.LinkToAttributeName = "EntityTwoid";

                ConditionExpression ce = new ConditionExpression();

                ce.AttributeName = "EntityTwoid";

                ce.Operator = ConditionOperator.Equal;

                ce.Values = new object[] { new Guid(EntityTwoid) };

     

                // Add the condition to the link entity.

                le2.LinkCriteria = new FilterExpression();

                le2.LinkCriteria.Conditions.Add(ce);

     

                // Add the from and to links to the query.

                le.LinkEntities.Add(le2);

                qe.LinkEntities.Add(le);

     

                RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();

                retrieve.ReturnDynamicEntities = true;

                retrieve.Query = qe;

     

                RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);

     

     

    Tuesday, November 4, 2008 9:24 PM
    Moderator
  • Hi,

     

    I am not sure what is that:

     

    le.LinkToEntityName = "EntityTwo_EntityOne";

    and

    le2.LinkFromEntityName = "EntityTwo_EntityOne";

     

    How I can find that name? When I am creating many to many relationship, new entity is created as well?

     

    When my secound entity is product what should I have as EntityTwo_EntityOne.

     

    // Create the link entity

    CrmSdk.LinkEntity le = new CrmSdk.LinkEntity();

    le.LinkFromEntityName = CrmSdk.EntityName.new_accountdongle.ToString();

    le.LinkFromAttributeName = "new_accountdongleid";

    le.LinkToEntityName = "EntityTwo_EntityOne";

    le.LinkToAttributeName = "EntityOneid";

    Tuesday, November 4, 2008 9:46 PM
  •  

    This is the intermediate entity created by CRM framework. look at your many to many relationship in relationshipd section of entity customization. it is usualy firstentity_secondentity. just a name concatenation.
    Tuesday, November 4, 2008 9:50 PM
    Moderator
  • Hi,

    When i am in RelationShip: AccountDongle to Product I can see only:


    Relationship Definition

    Name: new_new_accountdongle_product
    Relationship Entity Name: new_new_accountdongle_product

     

    So I am using new_new_accountdongle_product as "EntityTwo_EntityOne" but what in that case should be "EntityTwoid"?

    Is code below is right?

     

    CrmSdk.ConditionExpression ce = new CrmSdk.ConditionExpression();

    ce.AttributeName = "new_serialnumber";

    ce.Operator = CrmSdk.ConditionOperator.Equal;

    ce.Values = new object[] { "123456789" };

    // Create the link entity from opportuntiycompetiorsto competitor.

    CrmSdk.LinkEntity le = new CrmSdk.LinkEntity();

    le.LinkFromEntityName = CrmSdk.EntityName.product.ToString();

    le.LinkFromAttributeName = "productid";

    le.LinkToEntityName = "new_new_accountdongle_product";

    le.LinkToAttributeName = "productid";

    CrmSdk.LinkEntity le2 = new CrmSdk.LinkEntity();

    le2.LinkFromEntityName = "new_new_accountdongle_product";

    le2.LinkFromAttributeName = "new_accountdongleid";

    le2.LinkToEntityName = CrmSdk.EntityName.product.ToString();

    le2.LinkToAttributeName = "new_accountdongleid";

     

    // Add the condition to the link entity.

    le2.LinkCriteria = new CrmSdk.FilterExpression();

    le2.LinkCriteria.Conditions = new CrmSdk.ConditionExpression[] { ce };

    // Create a query expression.

    CrmSdk.QueryExpression qe = new CrmSdk.QueryExpression();

    qe.EntityName = CrmSdk.EntityName.new_accountdongle.ToString();

    qe.ColumnSet = new CrmSdk.AllColumns();

    // Add the from and to links to the query.

    le.LinkEntities = new CrmSdk.LinkEntity[] { le2 };

    qe.LinkEntities = new CrmSdk.LinkEntity[] { le };

    // Retrieve the roles and write each one to the console.

    CrmSdk.RetrieveMultipleRequest retrievequery = new CrmSdk.RetrieveMultipleRequest();

    retrievequery.Query = qe;

    CrmSdk.RetrieveMultipleResponse retrievedProduct = (CrmSdk.RetrieveMultipleResponse)myCrm.Execute(retrievequery);

    for (int i = 0; i <= retrievedProduct.BusinessEntityCollection.BusinessEntities.Length - 1; i++)

    {

    CrmSdk.product retrievedEntity = (CrmSdk.product)retrievedProduct.BusinessEntityCollection.BusinessEntitiesIdea;

    label1.Text = label1.Text + retrievedEntity.name.ToString();

    }

     

    thank you for help Smile

    Tuesday, November 4, 2008 10:11 PM
  • seems Ok to me. Try to debug and execute. When working try to add disassociate code in loop.

     

    Tuesday, November 4, 2008 10:16 PM
    Moderator
  • I think I found some wrong lines:

     

    CrmSdk.ConditionExpression ce = new CrmSdk.ConditionExpression();
    ce.AttributeName = "new_serialnumber";
    ce.Operator = CrmSdk.ConditionOperator.Equal;
    ce.Values = new object[] { "123456789" };

     

    Search have to be only by new_accountdongleid, so this should be like:

    CrmSdk.ConditionExpression ce = new CrmSdk.ConditionExpression();
    ce.AttributeName = "new_accountdongleid";
    ce.Operator = CrmSdk.ConditionOperator.Equal;
    ce.Values = new object[] { "5ad4ec4a-93a0-dd11-b92c-00065bfe50f3" };

     

    And also

     

    CrmSdk.LinkEntity le2 = new CrmSdk.LinkEntity();
    le2.LinkFromEntityName = "new_new_accountdongle_product";
    le2.LinkFromAttributeName = "new_accountdongleid";
    le2.LinkToEntityName = CrmSdk.EntityName.new_accountdongle.ToString();
    le2.LinkToAttributeName = "new_accountdongleid";

     

    But I still have that error:


    SOAP exception:
      0x80041103
      'New_accountdongle' entity doesn't contain attribute with Name = 'productid'.
      Platform
      System.Web.Services.Protocols.SoapException: Server was unable to process request.

     

    Tuesday, November 4, 2008 10:24 PM
  • Finally I get it Smile I had issue with that line as well:

     

    qe.EntityName = CrmSdk.EntityName.product.ToString();

     

    Anyway this is whole code which is working and as resault give me name of all products related to dongles.

     

    // Create the condition to test the opportunityid

    CrmSdk.ConditionExpression ce = new CrmSdk.ConditionExpression();

    ce.AttributeName = "new_accountdongleid";

    ce.Operator = CrmSdk.ConditionOperator.Equal;

    ce.Values = new object[] { "5ad4ec4a-93a0-dd11-b92c-00065bfe50f3" };

    // Create the link entity from opportuntiycompetiorsto competitor.

    CrmSdk.LinkEntity le = new CrmSdk.LinkEntity();

    le.LinkFromEntityName = CrmSdk.EntityName.product.ToString();

    le.LinkFromAttributeName = "productid";

    le.LinkToEntityName = "new_new_accountdongle_product";

    le.LinkToAttributeName = "productid";

    CrmSdk.LinkEntity le2 = new CrmSdk.LinkEntity();

    le2.LinkFromEntityName = "new_new_accountdongle_product";

    le2.LinkFromAttributeName = "new_accountdongleid";

    le2.LinkToEntityName = CrmSdk.EntityName.new_accountdongle.ToString();

    le2.LinkToAttributeName = "new_accountdongleid";

     

    // Add the condition to the link entity.

    le2.LinkCriteria = new CrmSdk.FilterExpression();

    le2.LinkCriteria.Conditions = new CrmSdk.ConditionExpression[] { ce };

    // Create a query expression.

    CrmSdk.QueryExpression qe = new CrmSdk.QueryExpression();

    qe.EntityName = CrmSdk.EntityName.product.ToString();

    qe.ColumnSet = new CrmSdk.AllColumns();

    // Add the from and to links to the query.

    le.LinkEntities = new CrmSdk.LinkEntity[] { le2 };

    qe.LinkEntities = new CrmSdk.LinkEntity[] { le };

    // Retrieve the roles and write each one to the console.

    CrmSdk.RetrieveMultipleRequest retrievequery = new CrmSdk.RetrieveMultipleRequest();

    retrievequery.Query = qe;

    CrmSdk.RetrieveMultipleResponse retrievedProduct = (CrmSdk.RetrieveMultipleResponse)myCrm.Execute(retrievequery);

    for (int i = 0; i <= retrievedProduct.BusinessEntityCollection.BusinessEntities.Length - 1; i++)

    {

    CrmSdk.product retrievedEntity = (CrmSdk.product)retrievedProduct.BusinessEntityCollection.BusinessEntitiesIdea;

    label1.Text = label1.Text + retrievedEntity.name.ToString();

    }

     

     

    THANK YOU FOR YOUR HELP

    Tuesday, November 4, 2008 10:27 PM