locked
CRM 2013 Online plugin, Retrieve then update entity RRS feed

  • Question

  • Hi,

    I am working on a CRM 2013 Online plugin, step message is Retrieve.  I am trying to retrieve current account then update an attribute.  I use QueryExpression to get the record and use service.Update(acct); to update.  The same code, if I register the step as Update, works.  However, registering as Retrieve does not update the field.  It does not throw out exception either.  Is Retrieve step for online CRM very different?

    EntityCollection Accounts = service.RetrieveMultiple(acctQuery);

                        foreach (Entity acct in Accounts.Entities)
                        {

                            if (acct.Attributes.Contains("description") == false)
                            {
                                acct.Attributes.Add("description", "anything");
                            }
                            else
                            {
                                acct["description"] = "something";
                            }

                            service.Update(acct);
                            
                        }

    Wednesday, January 14, 2015 6:54 PM

Answers

  • If you register the plugin on the Pre-Operation stage of the Retrieve message, then the "Entity" OutputParameter will contain the data that is returned to the caller, and you can modify this in your plugin

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

    • Marked as answer by chicago bq Thursday, January 15, 2015 8:09 PM
    Thursday, January 15, 2015 2:36 PM
    Moderator

All replies

  • If you do an Update of the record that you're Retrieving, then the updated data won't show up in the retrieved data, as CRM will have already have retrieved the data prior to the update. However, the update will be store in the database, and you'll see it in the next retrieve. Does this describe your scenario ?


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

    Wednesday, January 14, 2015 8:52 PM
    Moderator
  • Hi, David-

    Thanks, that makes sense.  In my case, however, even if I retrieved it second time, it still does not show the update of the field.  Let's put this aside.  Say, my requirement is to update the Description field in Account form.  I actually do not need to save the update in database, as long as the update show in Description field, that's good enough.  It's like doing javascipt stuff in plugin.  But, it has to be done in plugin, how to achieve it?

    Wednesday, January 14, 2015 9:34 PM
  • If you register the plugin on the Pre-Operation stage of the Retrieve message, then the "Entity" OutputParameter will contain the data that is returned to the caller, and you can modify this in your plugin

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

    • Marked as answer by chicago bq Thursday, January 15, 2015 8:09 PM
    Thursday, January 15, 2015 2:36 PM
    Moderator
  • Hi, David-

    Thanks for the answer.  All hassle came from Registration Tool profiler.  Debugging CRM Online plugin uses profiler sucks.  I am using Trace Services for debugging now.  It is slow but works like a charm.  Please do not use Registration Tool profiler.

    Thursday, January 15, 2015 8:13 PM