locked
Plugin problem when "creating order" from quote but not when creating order manually. RRS feed

  • Question

  • Hi,

    I'm in the process of creating a custom plugin that will perform the following steps:

    1. On create of salesorderdetail (Order>Product),
    2. If new_product_type = "Contract Product",
    3. Create a new grm_contract entity record and set various custom fields (with the values copied from salesorderdetail)
    4. Set lookup from salesorderdetail (grm_contract field) to the newly created grm_contract record.

    That's a very brief summary of my plugin.

    The plugin works fine when I create my order products manually through the order entity. The problem I have is that I run into trouble when I click the "Create Order" button from a quotation. My plugin states on screen that is has failed, when I download the log file it doesn't provide any obvious details.

    I've identified from my trace messages that the following lines of code are to blame. When I remove these lines, the plugin works as expected (without adding the lookup/reference (step 4) between the new contract record and salesorderdetail).

                            Guid contractId = service.Create(createcontract); // This works fine, left in to demonstrate how I get to the next step
    
                            // Update salesorderdetail with a reference to the newly created grm_contract record.
                            entity["grm_contract"] = new EntityReference("grm_contract", contractId);
                            service.Update(entity);

    Can anyone shed some light on why the "new EntityReference" and/or "service.Update(entity)" lines are causing an issue?

    Thanks,

    James



    • Edited by JamesGRM Monday, June 8, 2015 9:23 AM field name changes
    Monday, June 8, 2015 9:18 AM

Answers

  • Update: I've just disabled and then re-enabled the plugin step and my issue appears to have gone (without making any changes to the plugin.)

    Can anybody tell me if disabling/enabling a plugin is known to clear issues like this? Or am I more likely to have an underlying problem that will resurface from time to time? I'm thinking it could be performance related? Maybe my plugin is not getting the GUID of the newly created grm_contract record in time before trying to set the reference on the salesorderdetail record?

    Monday, June 8, 2015 4:17 PM

All replies

  • Hi JamesGRM,

    Actually when we convert Quote to order all the Quote products will create as Order products but what you are doing is before creating the order product you are trying to update the order product.

    I think you registered your plugin as pre-Operatoin.



    Monday, June 8, 2015 9:43 AM
  • Hi,

    The plugin is registered as a Post-operation in Synchronous execution mode against the salesorderdetail entity.

    Monday, June 8, 2015 9:50 AM
  • Can you post the error message?

    I am fairly certain that service.Update(entity); is where your code fails, can you debug your code f.e. by using remote debugging or the debug tool for CRM (Plugin Profiler)?

    https://crmbusiness.wordpress.com/2015/03/24/crm-2015-understanding-the-plugin-profiler-and-puzzling-error


    Halldór Jóhannsson



    Monday, June 8, 2015 11:01 AM
  • Enabling tracing (assuming it's Crm OnPremise) should also give an error message (assuming it's the Update call that's the problem). Most likely causes are:

    • You've got the attributename wrong - are you sure it's grm_contract, not grm_contractid?
    • You've not populated the Id property of the entity instance
    • You may get a SQL error, which is most likely due to locking. To modify an attribute of the entity on which the plugin fires (in this case salesorderdetail), it is preferable to use a pre-event, and just modify the Target InputParameter, rather than using an explicit Update. This avoid potential locking conflicts

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

    Monday, June 8, 2015 1:37 PM
    Moderator
  • Hi David,

    The plugin works fine when I create an order and its order products manually so therefore the attribute names are correct. I only get the error when clicking the "Create Order" button from a quote record.

    Also, it's CRM Online I'm using (sorry I didn't mention that previously.)

    Monday, June 8, 2015 4:02 PM
  • Update: I've just disabled and then re-enabled the plugin step and my issue appears to have gone (without making any changes to the plugin.)

    Can anybody tell me if disabling/enabling a plugin is known to clear issues like this? Or am I more likely to have an underlying problem that will resurface from time to time? I'm thinking it could be performance related? Maybe my plugin is not getting the GUID of the newly created grm_contract record in time before trying to set the reference on the salesorderdetail record?

    Monday, June 8, 2015 4:17 PM
  • It might have been some strange caching thing, sometimes inserting plugins again or restarting the service/computer/server fixes stuff like this.

    I doubt this will be resurfacing again (unless you make some changes).

    Better late than never 8)

    br

    Halldór


    Halldór Jóhannsson

    Thursday, October 15, 2015 4:57 PM