locked
how to find that the value of a filed has changed in plugin RRS feed

  • Question

  • Dear ALL;

    how to find that a particular field on the form has been change in the plugin i want run a plugin on the change of that particular filed on the form 

    Monday, June 18, 2012 11:02 AM

Answers

  • To fire the plugin on change of specific field select that field in plugin registration tool
    Filtering Attributes thus it will fire the plugin only on change of (Filtering Attributes) that field. 

    you can get new value from Traget and old value from image.


    NarSr If you find this answer as help ful please vote as helpful and if you find this as answer Please Mark It as Answer :)

    • Proposed as answer by Nar_mscrm Tuesday, June 19, 2012 6:15 AM
    • Marked as answer by anwar_addi Friday, July 13, 2012 1:05 PM
    Tuesday, June 19, 2012 5:36 AM

All replies

  • Hi Anwar,

    • Register a pre and a post image for your plugin step and make sure you select the attributes you need to compare
    • In your plugin, look and compare the values in context.PreEntityImages and context.PostEntityImages instead of context.InputParameters. Also, if the value is not in the post entity images then it has not changed.
    • You should register your plugin  in the post-operation stage because sometimes some fields are updated by the system after the main operation. When you register at the post-operation you have the exact values that will be stored in the entity and because it is still inside the transaction, if you throw a validation error, the main operation will be rolled back.

      Is this for the "statuscode" attribute? If so, that attribute cannot be changed by an "update" but a "setstate".

      Thanks

      T.Vinoth

    • Proposed as answer by Vinoth Thiru Monday, June 18, 2012 11:20 AM
    Monday, June 18, 2012 11:20 AM
  • You can use preimage and post image as suggested by Vinoth or choose filtering attribute as shown in this blog

    http://www.mscrmshop.blogspot.com.au/2012/02/use-of-filtering-attributes-during.html

    here is sample on how to use pre and post image to achieve the same

    http://www.mscrmshop.blogspot.com.au/2012/02/plugin-to-update-children-records-when.html

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com

    • Proposed as answer by Amreek Singh Monday, June 18, 2012 12:09 PM
    Monday, June 18, 2012 12:09 PM
  • anwar_addi,

    The best way to find out to see if your field is changed is by checking if the attribute exists in the "Target" entity. 

    var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
    if (((Entity) context.InputParameters["Target"]).Contains("new_attribute"))
    {
       // The value of new_attribute is changed
       // Do your logic here
    }

    You can also check it through Pre and Post Image, but that is adding unnecessary steps.

    With the Target entity, you don't need to register for Pre and Post Image.

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.


    Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"


    Monday, June 18, 2012 11:34 PM
  • To fire the plugin on change of specific field select that field in plugin registration tool
    Filtering Attributes thus it will fire the plugin only on change of (Filtering Attributes) that field. 

    you can get new value from Traget and old value from image.


    NarSr If you find this answer as help ful please vote as helpful and if you find this as answer Please Mark It as Answer :)

    • Proposed as answer by Nar_mscrm Tuesday, June 19, 2012 6:15 AM
    • Marked as answer by anwar_addi Friday, July 13, 2012 1:05 PM
    Tuesday, June 19, 2012 5:36 AM