locked
Call plugin on field onChange RRS feed

  • Question

  • Hello,

    I would like to call a plugin from onChange event of a field. My plugin code returns the string and I would like to display this value on the form. Could you please let me know how to do this? I appreciate any suggestion or code example.

    Thank you..

    Thursday, March 10, 2011 2:29 AM

Answers

  • You can register your plugin on Update of that attribute. It will work if you change and save attribute therefore put this line on change of field:-

    crmForm.Save();

     


    Regards Faisal
    • Marked as answer by anate Friday, April 8, 2011 5:01 PM
    Thursday, March 10, 2011 2:10 PM
  • Ya, Adding to Fizal.

    1. Register the plugin in Pre Update of that Entity.

    2. Use filtering attribute to register that plugin to run only when that field is changed.

    3. Since its pre update you can just add the string value (from your external WCF service) to the crm field by adding it in the entity property bag instead of updating it.

    4. There is no necessity to call crmForm.Save() in the OnChange() since it will save the form then and there and call the plugin. This might be a road blocker when there are mandatory fields to be filled.

    Let the plugin fire once the user clicks Save button, if its dosent affects the functionality.

    • Marked as answer by anate Friday, April 8, 2011 5:01 PM
    Thursday, March 10, 2011 2:16 PM
  • Ok.

    1. As Fisal suggested onChange of the attribute place javascript to save the record (check for the field value is not null and then perfrom crmForm.Save())

    2. Create a plugin (in pre update of that entity), which call your WCF servie and returns a String.

    say. string returnValue = <<invoke the methed of your WCF service>>;

    3. Add the value to the input property bag of your plugin context. say that your form attribute is "new_ReturnedString"

    StringProperty addReturnValue = new StringProperty("new_ReturnedString", returnValue);
    entity.Properties.Add(addReturnValue);

    Since its pre update event we dont need to explicitly update it. The values in the input property bag will be automatically get updated

    Note:

    1. Once the filed is changed the record will be saved.
    2. You can use filtering attribute (run plugin when that field alone is changed) in the plugin registration tool if you are too concerned about the performance.

    Reference:

    http://msdn.microsoft.com/en-us/library/cc151097.aspx

    http://www.mercureintegration.com/blog/post/2008/02/26/HOWTO-Working-with-Plugins-a-tutorial-using-the-Plugin-Registration-Tool.aspx

     

    • Marked as answer by anate Friday, April 8, 2011 5:02 PM
    Friday, March 11, 2011 7:32 AM

All replies

  • OnChange events process client-side javascript.  A plugin is triggered upon the firing of a server-side message (such as Create, Update, Delete etc).  One cannot directly access the other.

    What is it that you are trying to accomplish?


    --pogo (pat)
    Thursday, March 10, 2011 4:13 AM
  • Thank you for your reply. I am trying to call external WCF service from Plugin. This external WCF service returns string. If it is not possible via Plugin then what are the options do I have? Please let me know.

     

    Thursday, March 10, 2011 2:00 PM
  • You can register your plugin on Update of that attribute. It will work if you change and save attribute therefore put this line on change of field:-

    crmForm.Save();

     


    Regards Faisal
    • Marked as answer by anate Friday, April 8, 2011 5:01 PM
    Thursday, March 10, 2011 2:10 PM
  • Ya, Adding to Fizal.

    1. Register the plugin in Pre Update of that Entity.

    2. Use filtering attribute to register that plugin to run only when that field is changed.

    3. Since its pre update you can just add the string value (from your external WCF service) to the crm field by adding it in the entity property bag instead of updating it.

    4. There is no necessity to call crmForm.Save() in the OnChange() since it will save the form then and there and call the plugin. This might be a road blocker when there are mandatory fields to be filled.

    Let the plugin fire once the user clicks Save button, if its dosent affects the functionality.

    • Marked as answer by anate Friday, April 8, 2011 5:01 PM
    Thursday, March 10, 2011 2:16 PM
  • Thanks for the reply. There are no mandatory fields filled for this tab. Could you please explain more  about adding return value to property bag? Does it refresh the field when onChange() occurred? Can I check if the picklist field selected value  == "CreateNew" and then fire the plugin? I am new to CRM. Please bear with me.

    Thursday, March 10, 2011 2:50 PM
  • Ok.

    1. As Fisal suggested onChange of the attribute place javascript to save the record (check for the field value is not null and then perfrom crmForm.Save())

    2. Create a plugin (in pre update of that entity), which call your WCF servie and returns a String.

    say. string returnValue = <<invoke the methed of your WCF service>>;

    3. Add the value to the input property bag of your plugin context. say that your form attribute is "new_ReturnedString"

    StringProperty addReturnValue = new StringProperty("new_ReturnedString", returnValue);
    entity.Properties.Add(addReturnValue);

    Since its pre update event we dont need to explicitly update it. The values in the input property bag will be automatically get updated

    Note:

    1. Once the filed is changed the record will be saved.
    2. You can use filtering attribute (run plugin when that field alone is changed) in the plugin registration tool if you are too concerned about the performance.

    Reference:

    http://msdn.microsoft.com/en-us/library/cc151097.aspx

    http://www.mercureintegration.com/blog/post/2008/02/26/HOWTO-Working-with-Plugins-a-tutorial-using-the-Plugin-Registration-Tool.aspx

     

    • Marked as answer by anate Friday, April 8, 2011 5:02 PM
    Friday, March 11, 2011 7:32 AM
  • From your onchange javascript you can make a webservice call, add a certain entity, register your plugin to fire upon creation of the entity, within the Plugin Execute update the entity with the string you wanted, then again from the javascript call the webservice again to retrieve the new entity and hence the data string you just saved.

    This is a pretty funny workaround though.. and as the other have suggested it, depending on what you can do and have access to, you might just use the plugin directly (providing you have access to the code and can make the changes, debug, update, etc.) and fire it during an Update Step.

     

    Friday, March 11, 2011 11:41 PM