locked
Best Practices - Javascript of Plugin RRS feed

  • Question

  • Entities

    App, Prog, ProgType. 

    ProgType (1 - M) -> Prog (One ProgType can have multiple Progs)

    Prog (1 - M) -> App (One Prog can have multiple App). 

    Now, in my App entity, I have a look up to ProgType (new_progtypeid) as well. When the user modifies the Prog in the App entity, I want to auto-populate the lookup field to ProgType automatically based on the ProgType of the Prog. 

    I can do this either via JS or Plugin. The Solution Architect specified that has to be done via a JS. It is now complete. Now, we also have a requirement where an Option Field in ProgTypeClassification should be copied over to the App (in the App entity, it is available as new_apptype) as well. Now, this would mean that I will have to do another oData call for the ProgType id in order to get its attributes, i.e., there are two oData calls here - 

    1. To get attributes of Prog based on the ProgId as selected in the App form. This is done so that I can populate the new_progtypeid field in the App form. 

    2. Based on ProgType, I have to make another oData call so that I can get the ProgTypeClassification. 

    Both these fields (new_progtypeid and new_apptype) are Hidden fields in the App form. 

    In this scenario, is it better to use a Plugin rather than a JS? What are the best practices here?

    • Edited by CRMPadawan Tuesday, March 26, 2013 3:28 PM
    Tuesday, March 26, 2013 3:27 PM

Answers

  • If you need to set the value without the user saving the record JavaScript would be the only way as the plug-in won't fire until save is done.  Plugin is cleaner if you don't need that because it would work in all supported scenarios of changing that value, where as the JavaScript only would work with the standard CRM forms.  Meaning if a workflow changed the value, or you had a custom mobile app for example you would have to ensure the same business logic ran - where the plug-in would run in all of those scenarios


    .NET MVP / Microsoft Regional Director / http://blog.davidyack.com / http://crm.davidyack.com

    • Marked as answer by CRMPadawan Tuesday, March 26, 2013 6:06 PM
    Tuesday, March 26, 2013 5:22 PM

All replies

  • There probably isn't a right or wrong answer. 

    A few things...

    Use JavaScript if:

    • You need to make changes on the fly (easier to change JavaScript than a plugin)
    • You need a change to immediately be visible to the end user
    • You have limited .NET experience

    Use plugin if:

    • Code is more complex in nature
    • Change does not need to be reflected to end user while editing
    • You need to execute code after the record has saved (post update)

    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, March 26, 2013 4:13 PM
    Moderator
  • Jason, 

    Thanks! I do realize that there is no right or wrong answer here and that is one of the greatest benefits / disadvantages of Dynamics CRM and the general guidelines are quite helpful, however, is there a technical reason to prefer one over the other in my scenario. Let me try and present my side of the argument. 

    In favor of plugin: 

    1. The fields are Read Only / Not Visible fields (as you pointed out) which are populated so that they can be used in Workflows (OOB / Custom). 

    Well, that is the only thing I have apart from two oData calls in a JS for updating two hidden fields, seemed a bit unnecessary. 

    I am using retrieveRecord (provided as part of SDK), and this returns the entire record - however, I require just one field. Can I do that sort of an activity via a JS because, a plugin yields is much better for returning just the specific column. 

    Also, in this instance, using a JScript makes a call to the server (async) twice and then saves the record...whereas if I use a plugin, the code runs at the server and updates the fields thereby reducing the two calls to the server. 

    Statutory Disclaimer: My understanding of the CRM 2011 architecture is minimal as it is just been a little over 2 months with the tool, so, pardon me if I come across like an illiterate. ;-)

    Slight disagreement on - Use JS if you have limited .NET experience, lack of experience in a technology is a good experience to learn it not choose something else. My humble 2 cents. 



    • Edited by CRMPadawan Tuesday, March 26, 2013 4:42 PM
    Tuesday, March 26, 2013 4:41 PM
  • If you need to set the value without the user saving the record JavaScript would be the only way as the plug-in won't fire until save is done.  Plugin is cleaner if you don't need that because it would work in all supported scenarios of changing that value, where as the JavaScript only would work with the standard CRM forms.  Meaning if a workflow changed the value, or you had a custom mobile app for example you would have to ensure the same business logic ran - where the plug-in would run in all of those scenarios


    .NET MVP / Microsoft Regional Director / http://blog.davidyack.com / http://crm.davidyack.com

    • Marked as answer by CRMPadawan Tuesday, March 26, 2013 6:06 PM
    Tuesday, March 26, 2013 5:22 PM
  • David: Thanks, in this scenario, no...I do NOT need to set the value without user saving the record. I want those two fields to be populated only as part of the save. So, a plugin would be a better implementation for this particular requirement.
    Tuesday, March 26, 2013 6:06 PM