Skip to main content

MSCRM Plugin Vs Workflow


In Dynamics CRM, workflows and plugins are used to automate business processes.They allow businesses to hook onto events that occur in the system. Here we will look at the differences between the two and when to use which one.
Looking in Dynamics CRM in our default solution, we see Processes and Plug-in Assemblies.
Processes are where our workflows are located, along with actions and business process flows.
You can see there are several processes below:
Let’s take a look at one of these – Auto Response Email for Case:
As can be seen, this workflow will run on the Case entity when a record status is changed, and it will run in the background. The logic says:
  • If the case status is resolved, send a new email message and stop the workflow
  • Otherwise, stop the workflow
Opening the first step, we can see we have an email template, where we can add the from and to as dynamic values from the case itself. The message of the email allows for text and dynamic values as well.
Note the workflow was activated. If we disable the workflow by pressing Disable, we will be able to edit the workflow. We can add more steps to the workflow.
For example, if we wanted to update another record as a result of the case being resolved, we could add a “Update Record” step. We could also run a child workflow or perform an action.
You can see workflows are useful for tasks such as updating data, and can be triggered when you save/delete/update records and fields.
The workflow is set to run in the background:
What this means, is the workflow will run asynchronously. If this box was unchecked, the workflow would run synchronously and the system would wait for its completion. You can also convert to a real-time workflow by clicking a button:
The scope of the entity defines who can run the workflow. If you want your workflow to run on any record in the organization you would set it to Organization.
Workflows are also triggered off certain events:
Workflows do not run offline. I.e. if you are using the CRM Outlook Client in offline mode, workflows won’t run until you come back online as they need to access the CRM server.
A key thing to note is that the workflows described above do note require development. A business user can go in and set up a workflow.
Now let’s discuss Plugins.
Plugins are different from workflows in CRM. Here you can see we have some plugins registered in the system:
Plugins are .NET code that is written by developers. As such, there is a lot you can do with a plugin, such as integrating with different systems. Plugins can run synchronously or asynchronously.
Plugins are written in Visual Studio and then deployed using the Plugin Registration Tool. This is located in the CRM SDK in the SDK\Tools\PluginRegistration folder.
You register the assembly created in Visual Studio and then register a step that defines what happens. Here you define which assembly the plugin should fire on (primary and secondary entities) and on what event (the message). Events include Assign, Create, Delete, Retrieve, Retrieve Multiple, Update, GrantAccess, RetrievePrincipalAccess, SetState and more. You can see there are more events available that workflows.
Check out this link from Microsoft for more information: https://msdn.microsoft.com/en-us/library/gg328576.aspx
One of these events will need to run in order for the plugin to fire, i.e. there is no “on demand” running like there is with workflows.
When registering the plugin, you have several options:
You can see here, you can define when the plugin should run. The options are:
  • Pre-validation. Runs before anything else
  • Pre-operation. Runs after validation and before committing to the database
  • Post-event. Runs after record committed to the database
A main advantage with plugins is that they work in an offline environment, which is different from workflows which cannot.
Both plugins and workflows work in an on-premise and online environment.
In summary, when to use a workflow or a plugin depends on requirements.

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...