locked
[CRM4] Update triggering entity with retrieved data in child pipeline, is it even possible? RRS feed

  • Question

  • Introduction

    I have created a lookup field for
    subject and salesorderdetail, don't ask why but we need it. Wink
    At first I created a JScript function which retrieved the subject from the product by using the webservices.
    This worked well, but it only filled in the form, not the lookup attribute of the entity itself.
    So I decided to write a plugin which would automatically fill in the subject on the salesorderdetail when it was created or updated. This worked perfectly in the parent pipeline, the child pipeline is another story I'm afraid.

    Of course you can't create a CrmService object in the child pipeline, it is said that you can easily create deadlocks by doing so. So I used the GetCrmServiceInChildPipeline function from the PluginHelper file and modified it a bit. Now I can create a CrmService object.

    Trying Pre-Event Synchronously

    When I register the plugin for synchronous pre-event execution it is no problem at all to modify the subject lookup.
    The retrieving of the value of the subject lookup from the linked product entity seems impossible.
    I have tried many ways of retrieving the product entity so I could get the subject from it.
    The first method was using QueryByAttribute, then I tried the Retrieve method and finally I used the RetrieveRequest with TargetRetrieveDynamic.
    It seems that there is going wrong which even the Crm application does not understand. It gives me an SQL Server error.
    Strangely enough there is no error in the trace logs. I managed to find an ASP error in the log viewer but that did not give me more information. I cannot find a stacktrace or SQL syntax error so I have no clue how to solve this.

    Trying Post-Event Asynchronously

    Then I tried the other option, when using the post-event asynchronously I was finally able to retrieve the product from the salesorderdetail. Now I ran into another problem.
    When trying to update the salesorderdetail entity the CrmService gave me the following error:

    "The product and the unit cannot be updated while the entity is locked."

    Which makes no sense to me, I am not updating the product and the unit, also I have never seen this error before.
    Trying different means of updating the entity did not help.

    Is it even possible?

    So after trying alot and searching for clues I ran out of options.
    I can of course create a workaround by updating other entities, using workflows or go back to JScript but before I yield to those 'dirty' option I'd like to be sure that I've done everything that is possible.
    Thursday, June 5, 2008 8:06 AM

Answers

  • Hi Gonadan,

     

    I think it is possible - after a lot of playing around it seems that CRM believes a lookup field has changed if the property contains a value when you call update.

     

    Eg.

    // Save the current Sales Order Line

    lservice.Update(entity);

     

    Triggered

    >Crm Exception: Message: The product and the unit cannot be updated while the entity is locked., ErrorCode: -2147206371

     

    But if I remove the Product and Unit properties prior to calling update the problem appears to be solved

     

    // Remove the Properties from the entity if they exist

    if (entity.Properties.Contains("productid"))

    {

    entity.Properties.Remove("productid");

    }

    if (entity.Properties.Contains("uomid"))

    {

    entity.Properties.Remove("uomid");

    }

    // Save the current Sales Order Line

    lservice.Update(entity);

     

    You'll also have to remove the Price details etc. or you will get the following:

    >Crm Exception: Message: The price cannot be overridden while the entity is locked., ErrorCode: -2147206371

    Monday, October 27, 2008 8:41 AM

All replies

  • workflows to use the workflow assembly, it will be best option for update and then trigger other events.

     

    REgards,

    Imran

     

    msn : mscrmexpert@gmail.com

     

    Thursday, June 19, 2008 12:21 PM
    Moderator
  • Hi Gonadan,

     

    I think it is possible - after a lot of playing around it seems that CRM believes a lookup field has changed if the property contains a value when you call update.

     

    Eg.

    // Save the current Sales Order Line

    lservice.Update(entity);

     

    Triggered

    >Crm Exception: Message: The product and the unit cannot be updated while the entity is locked., ErrorCode: -2147206371

     

    But if I remove the Product and Unit properties prior to calling update the problem appears to be solved

     

    // Remove the Properties from the entity if they exist

    if (entity.Properties.Contains("productid"))

    {

    entity.Properties.Remove("productid");

    }

    if (entity.Properties.Contains("uomid"))

    {

    entity.Properties.Remove("uomid");

    }

    // Save the current Sales Order Line

    lservice.Update(entity);

     

    You'll also have to remove the Price details etc. or you will get the following:

    >Crm Exception: Message: The price cannot be overridden while the entity is locked., ErrorCode: -2147206371

    Monday, October 27, 2008 8:41 AM