Skip to main content

Dynamics CRM: What is difference between Workflows, JavaScript, Plugins ?

There are three ways to automate actions in Microsoft Dynamics CRM: workflows, JavaScript, or plugins. In this blog we will discuss the difference between them and how to choose which option is appropriate for your task.
  • Workflows can perform tasks such as updating data or sending email. They are triggered by saving records, creating records, or changing specific fields on a form, and once triggered, they run on their own in the background. As you can see in the example of How to Assign a Territory to a Lead in Dynamics CRM, you can even look up data in another entity.

  • JavaScript runs on the screen while the user is using a form. JavaScript is triggered by events within the page, updating a field or saving, and it is commonly used to hide or show different fields on the forms. You can also, for instance, Populate a CRM 2011 Lookup or PartyList Field Using JavaScript by having a lookup automatically linked to the record based on what is entered in another data field.

  • Plugins are separate .Net programs that respond to saving records or creating records. They can be set to run immediately on the screen or on their own behind the scenes depending on the need. Plugins are often used to do advanced tasks because they can be programmed to do anything within the limits of .Net and the SDK.
So, how do you decide using workflows vs. JavaScript vs. plugins when so there are many ways to update the information you want? There are a few factors to help the decision:
  • Does the user need to see the results before moving on?
    This is known as synchronous processing. If the user needs to see the change on the screen, it should be done with a plugin or JavaScript and not a workflow. A workflow can take several seconds or minutes to process and should not be used in a process where users must wait for it to complete before they can continue.
  • Who will the maintenance fall to? Users or IT?
    Workflows are much easier for business users to modify than JavaScript or plugins, which require some code. JavaScript or plugins should be avoided in processes that may change frequently.
  • Does it need to be run on demand or only responding to system events?
    Workflows can easily run on demand (a.k.a manual workflow), but JavaScript and plug-ins require custom buttons in order to run on demand.
  • What is the relationship between the primary record and the records that need to be updated?
    Workflows can update records with a N:1 relationship (a lookup on the record), but they cannot run on 1:N relationships (those on the left navigation or in a sub-grid). So using a workflow, you cannot automatically update all the contact addresses when the parent account address changes. But this can be done with a plug-in.
Here is a table that will help you identified the difference between workflows, JavaScript, and plugins for use within Microsoft CRM.
WorkflowJavaScriptPlugin
SynchronousAsynchronousSynchronousEither
Can Get External DataNoYesYes
MaintenanceBusiness UsersProgrammersProgrammers
Can Run AsUserUserCRM System
On DemandYesNoNo
Nested Child ProcessYesNoYes
Executed After SavingAfterBeforeAfter
TriggersCreate, Field Change, Status Change, Assign to Owner, On DemandField change or Form LoadCreate, Field Change, Status Change, Assign to Owner, Delete
For different cases when the user may need to walk through a process and make decisions, dialogs may instead be the right answer. 

Comments

Popular posts from this blog

Microsoft Dynamics 365 CRM Troubleshooting Solution Import Errors

Remember when CRM life was so much simpler that solutions did not yet exist? If you had separate development and production environments and you wanted to move your customizations, you simply clicked  Export Customizations  and voila! It was done. Those were the days. Nostalgia Warning – in case you’ve forgotten, here’s a screenshot to jog your memory: With CRM 2011, the concept of solutions was introduced, giving us a new set of powers – by picking individual entities, workflows, etc., we now had the ability to group together and move only those customizations we wanted to include in our solution. The next great solutions advancement came with CRM 2016: we can now select specific components within each individual entity – so instead of moving the entire contact entity, for example, we have the option of moving only a certain view or field within the entity. And we can do this without having to hack the xml in the zip file. (By the way, if you want to learn more abou...

How to Filter SubGrid Lookup view in Dynamics 365 CRM

How to Filter SubGrid Lookup view in Dynamics 365 CRM.  Please check the comments in the below code and do follow the steps accordingly and call the  filterSubGrid() funtion on onload. var LastQuery = ""; function filterSubGrid() { debugger; setSubgridLookupFiltering(); } function AddLookupFilter(entity_type, customFilter) { var subgridLookup = Xrm.Page.getControl("lookup_Contacts_Participants"); subgridLookup.addCustomFilter(customFilter, entity_type); } function setSubgridLookupFiltering() { var subgridAddButtonId = "Contacts_Participants_addImageButton"; //Try to get the element from both the current and the parent document. var subgridAddButton = document.getElementById(subgridAddButtonId) || window.parent.document.getElementById(subgridAddButtonId); //This script may run before the subgrid has been fully loaded on the form. If this is the case, //delay and retry until the subgrid has been loaded. if (subg...

How to prevent record from saving in Dynamics CRM using Javascript

  From time to time you might need to add some validation to the save event of an entity, this actually used to be an approach I would use on a regular basis but since the introduction of business rules have found myself doing this less and less. But still, knowing the ability is available is handy. When you define the onsave event function, you must tick the “Pass execution contact as first parameter” option. (See below) Having done that you can create an onSave function with code similar to the example I have shown below. Note forgetting the “(context)”, which will take the context parameter allowing you to prevent the save when needed. function onSave(context) { var saveEvent = context.getEventArgs(); if (Xrm.Page.getAttribute("telephone1").getValue() == null) { // *** Note: I am using an alert for testing a notification maybe better! alert("Put in a phone number!"); saveEvent.preventDefault(); } } Note: This simple example might be better achi...