locked
CRM 2013 Quote Product Plugin Issue. RRS feed

  • Question

  • Hi CRM Gurus,

    I am running into an issue and wanted to see if anybody knows what’s going wrong here. We had a CRM 2011 Solution on which we had two plugins on our Quote Product entity. The plugins are PreQuoteProductCreate and PostQuoteProductUpdate. We set some of our custom fields during plugin execution. We have recently ported this solution to CRM 2013 and noticed that when I add quote products via the new Inline Editable grid view (Products in below screenshot) the block of code that fills those fields in the plugin doesn’t fill up those fields. (See code snippet below the else block is not doing what is expected of it to do)

    if (postImageQuoteDetail.Attributes.ContainsKey("productdescription"))
                {
                    // Write in product
                    postImageQuoteDetail.Attributes["axsi_productid"] = postImageQuoteDetail.Attributes["productdescription"];
                    postImageQuoteDetail.Attributes["axsi_productdescription"] = postImageQuoteDetail.Attributes["productdescription"];
                }
                else
                {
                    EntityReference productReference = postImageQuoteDetail.Attributes["productid"] as EntityReference;
                    localContext.Trace("ConnectorExecution: ProductId: " + productReference.Id);
    
                    Entity productEntity = localContext.OrganizationService.Retrieve("product", productReference.Id, 
                        new ColumnSet("productnumber", "name", "producttypecode", "axsi_itemorcategoryintegrationkey"));
                    localContext.Trace("Product number: " + productEntity.Attributes["productnumber"]);
    
                    postImageQuoteDetail.Attributes["axsi_productid"] = productEntity.Attributes["productnumber"];
                    postImageQuoteDetail.Attributes["axsi_productdescription"] = productEntity.Attributes["name"];
                    postImageQuoteDetail.Attributes["axsi_producttypecode"] = productEntity.Attributes["producttypecode"];
                    postImageQuoteDetail.Attributes["axsi_itemorcategoryintegrationkey"] = productEntity.Attributes["axsi_itemorcategoryintegrationkey"];
                }
    

    However when I add the Quote Product from our old CRM 2011 Quote Product form on CRM 2013. The fields are populated correctly. I suspect is it because the new inline grid view experience with product add doesn’t have a “productid” lookup anymore based on which we are doing our query and updating those fields. Could this be the issue? Any help around this would be appreciated.

    Wednesday, February 19, 2014 1:21 AM

All replies

  • Hi,

    The Quote product still has the concept of write in or existing products - with the existing product populating the productid.

    I suggest that you first establish that the plugin is firing - you could throw and exception to get the trace information to confirm this is happening if you can't attach a debugger or enable platform tracing (because you are Online and not OnPrem).

    Hope this helps,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, February 19, 2014 9:21 AM
    Answerer
  • Thanks for the reply Scott, The plugin indeed does fire. So when I add a write-in product the following code in my "if" block does fire and sets up my custom fields. It's only when I chose an existing product only than when it goes to the "else" block in my code it doesn't do anything no error message nothing but the fields are not populated.

                    // Write in product
                    postImageQuoteDetail.Attributes["axsi_productid"] = postImageQuoteDetail.Attributes["productdescription"];
                    postImageQuoteDetail.Attributes["axsi_productdescription"] = postImageQuoteDetail.Attributes["productdescription"];

    
                    // Write in product
                    postImageQuoteDetail.Attributes["axsi_productid"] = postImageQuoteDetail.Attributes["productdescription"];
                    postImageQuoteDetail.Attributes["axsi_productdescription"] = postImageQuoteDetail.Attributes["productdescription"];
    Wednesday, February 19, 2014 6:40 PM
  • Hi,

    Looking at the code again it seems that you are updating the postImage (postImageQuoteDetail) when you should be updating the Target entity :

    if (context.InputParameters.Contains("Target") &&
        context.InputParameters["Target"] is Entity)
    {
        // Obtain the target entity from the input parameters.
        Entity entity = (Entity)context.InputParameters["Target"];

    Set the values on the entity rather than your post image.

    Hope this helps,

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, February 19, 2014 7:46 PM
    Answerer
  • if (entity.Attributes.ContainsKey("productdescription")) { // Write in product entity.Attributes["axsi_productid"] = entity.Attributes["productdescription"]; entity.Attributes["axsi_productdescription"] = entity.Attributes["productdescription"]; } else { EntityReference productReference = entity.Attributes["productid"] as EntityReference; localContext.Trace("ConnectorExecution: ProductId: " + productReference.Id); Entity product = localContext.OrganizationService.Retrieve("product", productReference.Id, new ColumnSet("productnumber", "name", "producttypecode", "axsi_itemorcategoryintegrationkey")); localContext.Trace("Product number: " + product.Attributes["productnumber"]); entity.Attributes["axsi_productid"] = product.Attributes["productnumber"]; entity.Attributes["axsi_productdescription"] = product.Attributes["name"]; entity.Attributes["axsi_producttypecode"] = product.Attributes["producttypecode"]; entity.Attributes["axsi_itemorcategoryintegrationkey"] = product.Attributes["axsi_itemorcategoryintegrationkey"]; }

    Tried the code above, still it would fill it for the  "if" case when its an existing product and it goes in the else block the values never get set, although values are there in Product entity.

    Usman

    Wednesday, February 19, 2014 8:02 PM
  • Hi,

    For this to work, the plugin must be registered on the pre stage not the post stage.

    Scott


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, February 19, 2014 8:06 PM
    Answerer
  • This Plugin infact runs on "PreQuoteProductCreate" so yes its on the pre stage.
    Wednesday, February 19, 2014 8:33 PM
  • Very strange - what I don't understand is why it would work for some attributes (in the if block) but not the else block. 

    Do you have any plugins registered on the Post stage that does an update to the product item?


    Scott Durow
    Blog www.develop1.net    Follow Me
    Rockstar365
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, February 19, 2014 8:40 PM
    Answerer
  • Something that I would try if I was stuck in this position is to put a "throw new InvalidPluginExecutionException" under the if and the else statements with different messages in them. Then I know if it is indeed doing something in the if and else statements then from there I at least have a start at where my problem is. Not sure if you have tried something like this already, but just trying to help. I have several plugins like this in 2011 and we are looking to upgrade to 2013 this year so I'm interested in this issue.

    Wednesday, February 19, 2014 9:06 PM
  • Something else to consider is wheter AutoSave is enabled (which it is by default). I don't know if it affects the behaviour of the inline grid, but it can affect existing plugins that exepct all fields to be populated at the same time. If AutoSave is currently enabled, I'd suggest disabling it temporarily to see if it affects the plugin behaviour

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

    Wednesday, February 19, 2014 9:19 PM
    Moderator
  • I have a plugin on PostQuoteProductUpdate. Nothing updating to the product item here.

     protected void ExecutePostQuoteProductUpdate(LocalPluginContext localContext)
            {
                if (localContext == null)
                {
                    throw new ArgumentNullException("localContext");
                }
    
                if (localContext.PluginExecutionContext.PostEntityImages == null ||
                    !localContext.PluginExecutionContext.PostEntityImages.Contains(this.postImageAlias))
                {
                    //throw new ApplicationException("Required PostEntityImages not found");
                    return;
                }
                localContext.Trace("ConnectorExecution: Required PostEntityImages found");
    
                Entity postImageQuoteDetail = localContext.PluginExecutionContext.PostEntityImages[this.postImageAlias];
    
                // Verify that the entity is the correct type
                if (postImageQuoteDetail.LogicalName != "quotedetail")
                {
                    return;
                }
                localContext.Trace("ConnectorExecution: target is a quote product");
    
                if (postImageQuoteDetail.Attributes.ContainsKey("productdescription"))
                {
                    // Write in product
                    postImageQuoteDetail.Attributes["axsi_productid"] = postImageQuoteDetail.Attributes["productdescription"];
                    postImageQuoteDetail.Attributes["axsi_productdescription"] = postImageQuoteDetail.Attributes["productdescription"];
                }
                else
                {
                    EntityReference productReference = postImageQuoteDetail.Attributes["productid"] as EntityReference;
                    localContext.Trace("ConnectorExecution: ProductId: " + productReference.Id);
    
                    Entity productEntity = localContext.OrganizationService.Retrieve("product", productReference.Id, 
                        new ColumnSet("productnumber", "name", "producttypecode", "axsi_itemorcategoryintegrationkey"));
                    localContext.Trace("Product number: " + productEntity.Attributes["productnumber"]);
    
                    postImageQuoteDetail.Attributes["axsi_productid"] = productEntity.Attributes["productnumber"];
                    postImageQuoteDetail.Attributes["axsi_productdescription"] = productEntity.Attributes["name"];
                    postImageQuoteDetail.Attributes["axsi_producttypecode"] = productEntity.Attributes["producttypecode"];
                    postImageQuoteDetail.Attributes["axsi_itemorcategoryintegrationkey"] = productEntity.Attributes["axsi_itemorcategoryintegrationkey"];
                }
            }


    Wednesday, February 19, 2014 10:40 PM
  • Tried turning off the AutoSave but still the issue persists.
    Wednesday, February 19, 2014 10:41 PM
  • So this is very strange, I added a throw new InvalidPluginExecutionException in the else block of my code, when I do it via the Inline editable grid and add an existing product it won't throw the exception. However when I follow the old route of going to Products and than adding the Quote product like we used to do in CRM 2011 I can see my exception on preQuoteProductCreate. Very very Strange indeed.
    Wednesday, February 19, 2014 11:07 PM
  • That's what I suspected was happening. So you know where the issue persists, for some reason it sounds like the code always thinks the "productdescription" contains some value.
    Thursday, February 20, 2014 4:07 PM
  • Have you thought about instead of checking if the "productdescription" value, check the "isproductoverriden" value? Since it is a yes/no option there is always a value. You can say if it equals yes do this else do that? Then you might be able to get around whatever issue you are having now. Or maybe 2013 got rid of that option?
    Thursday, February 20, 2014 8:52 PM
  • I don't know if this may work, but can you register in PreValidation of Update?
    Thursday, February 20, 2014 10:24 PM