Callbacks from MS Dynamics CRM to a webservice - dynamics-crm

We're building a system that is tightly integrated with a clients CRM install, and need to have a callback fired when an entity is updated, created or deleted. This callback will ideally send the entity name and id to an external service via a HTTP get request.
I've not found any docs online that help - can anyone point me in the right direction?

You're looking for plugins: http://msdn.microsoft.com/en-us/library/dd393295.aspx.
You can register a plugin on Create, Update, Delete, etc. of an entity, and then run any custom code you'd like. You'll definitely have access to the entity name and the id, as well as fields that were updated, information on the user who initiated the call, etc.
Just know that in MSCRM 3.0 & 4.0, plugins run outside the actual database transaction, so it's possible the event could fire in CRM, but the plugin fails and the event still goes through. In MSCRM 2011, they run inside the transaction, and can stop the CRM event from happening if need be.

Related

Plugin is not triggering on User Enable/Disable

I am using Dynamics 365 Online Trial. I have a requirement to trigger a plugin when the user is disabled/enabled in CRM. So I have created the plugin and registered the same in User entity SetState and SetStateDynamicEntity messages but the plugin is not triggered.
Plugin Registration Steps:
Message: SetState & SetStateDynamicsEntity
Entity: systemuser
Event: Post-Operation
User records have been Enabled/Disabled in CRM (through O365) but the plugin is not triggered.
Also tried with update message plugin for the same requirement, but that is also not triggering the plugin.
Updated Plugin Registration Steps:
Message: Update
Entity: systemuser
Event: Post-Operation
Filtering Attribute: All Fields
Image: Pre Image
Any help would much be appreciated.
You are on the right track to be using the Update message, as the use of SetState is deprecated (as far as I know).
You might find this article interesting. It states:
When update requests are processed that include both state/status
fields plus other standard fields, workflows registered for the Update
message execute once for all non-state/status fields, and then once
for the state/status fields. Workflows registered for the Change
Status step continue to be triggered by updates to state/status
fields.
However, users may be a little different as they have the isDisabled field. Maybe try filtering the trigger to just that field. And if that doesn't work, try triggering on a "regular" field just to make sure that you plugin can fire on the Update message.
Full disclosure: I have never had to write a plugin that fires on disable of a user.
However, since it does not seem to be firing when filtered down to isDisabled, I checked to see if an OOB workflow could trigger on that field. It is missing from the selection dialog, so apparently not:
You might want to get a Microsoft support ticket going to see what they say, but in the meantime, perhaps register it to trigger on ModifiedOn, with a pre-image and check for yourself whether isDisabled changed.
We also experienced this issue, we were unable to achieve the plugin route.
Then we did a workaround scheduled job (to run every 24 hours) with SSIS + Kingswaysoft package to query the disabled users.
This system user status change is not getting trapped in Dynamics platform as we are not sure how the O365 changes like license removal or AD changes like account removal is getting replicated into Dynamics platform.
You can try registering a plugin on Update of userlicensetype is SystemUser entity

Using a Workflow to auto-populate a form field upon creation in CRM 2011

I would like to have a field automatically be populated with something I define in a workflow. Currently I have the workflow running upon record creation, however the field is only populated AFTER the user saves the record for the first time.
How can I use a workflow to populate that field before the user saves the form?
You can't. Workflows function on the server-side, but you're asking about populating a client-side field before the server is contacted. Moreover, workflows are triggered asynchronously, which by definition means the record has to be created in advance.
You'll need to either attach a JavaScript function to the OnSave event, or trigger the population of the field in a pre-validation or pre-operation .NET plugin. I suppose you could use a Dialog as well, but that would require user input. See the below links for more detail on the differences between plugins, workflows, and dialogs.
Options: Plugin, Workflow or Dialog
Automate Business Processes in Microsoft Dynamics CRM

CRM 2011 Plug-in chaining

Just a quick question I wasn't able to Google-fu about CRM 2011 plug-in behavior. If I have a plug-in on, let's say Account, that updates another entity, let's say Contact, plug-ins registered on Contact messages will fire (correct?).
If those plug-ins are registered as synchronous will the Account plug-in have to wait for the Contact plug-ins to finish executing before it's execution is completed? Does the chaining of the plug-ins create a blocking situation?
Chris,
To your first question that plugins registered on Contact messages will fire? That is correct. and if you have selected synchronous that meaans:
The account plugin gets triggered makes some changes to the contact entity, and then the contact entity plugin makes some changes to contact entity. Only if the contact plugin finished without error then all the changes will apply, if not the contactplugin does a roll back aswell as the Account plugin. So no changes will be applied.
With Asynchronous it means that if the account plugin is finished, regardless if the contact plugin finishes without error, the changes apply to the contact entity.

Can an arbitrary email address be used in workflow send email activity

I'm wondering if there is any way to be able to include an arbitrary email address as the To:, From:, CC: or BCC: fields of a send email activity? It appears that they must be contacts in the CRM.
I ask this because I have a requirement to cc a known group email (no actual user associated with the email...something like support#mycompany.com...though it's not a queue at all). I'm concerned that if I create a CRM user for this email, that when I move to production, I'll have to change all the workflows using this email to point to the CRM entity on the production box (assuming GUID is saved with activity).
If an arbitrary email isn't possible, any other suggestions?
I'm not quite sure, if I have unterstood your question right:
You want to create a workflow which contains a send mail activity. You would like to set one of the address fields (To:, From:, CC:) to a plain mail address like 'foo#bar.org'?
It is possible if
you enter the mail address by hand (do not use the field assistant)
you have configured that e-mails with unresolved recipients are allowed to be sent.
See Settings -> Administration -> System Settings -> E-Mail Tab
you don't want to set the e-mail address with another workflow step
To my knowledge, the only way to do this would be to create a custom workflow assembly. This may be more trouble to you than it's worth.
I doubt it. Not without horrible SDK or Custom Workflow Activity machinations, which even then may not work. Unless you have a truly gargantuan number of workflows that must be altered, the manual approach may be the best.
It may be a terrible hack, but you might be able to replace instances of the development environment support account GUID with its production counterpart directly in SQL Server. Not in the SystemUserBase table, but in whatever workflow activities mention the support account as a CC field in an e-mail. But that is scary stuff.
You may also want to take another look at your process; a significant portion of Dynamics CRM is dedicated to handling support issues, and that includes fairly robust e-mail tracking and storage; there probably shouldn't be a need to CC this support mailbox to which you refer.
In summary: All of the options I've listed are terrible. Find a way to avoid them. :-P
I've had this requirement before, and even with workflow activities, there doesn't seem to be a way to handle this (even though CRM will allow it through the UI).
Your instinct is right that if you create a user separately in both environments and then try to move a workflow that references that user between the environments, that the workflow references will have to be updated.
The best solution, to me, would be to go with just creating the contact/user in one environment. But then, create the contact/user in your other environments with the same Guid. You can do this through the API quite easily, or for a no-code solution, there is a Microsoft provided CRM Configuration Data Utility (http://msdn.microsoft.com/en-us/library/dd442453.aspx) that you can use. (Note that the utility will want to migrate all records from the chosen entity, so you might want to export it to a file, edit the resulting file which is just XML, and then import to your target).
This is something that you can do with CRM 2011, CRM 2013, or CRM 2015 if you have a custom entity that is email enabled and then copy the email address from your core entity even if that email address is in a custom text field to it and relate it back via a lookup field. Doing that would require a plugin in Microsoft CRM 2011, but is possible to do with real-time workflows in Microsoft CRM 2013 and Microsoft CRM 2015. This method would allow you to have email addresses associated to the records and available for usage with the CRM workflows to send emails without needing to create an additional user or contact record. This is also handy if you are working with an entity like Incidents that is a core CRM entity and is not email enabled, yet you wish to be able to send emails related to that entity. You could use this method in conjunction with the steps ccellar provided.
I've got a blog post that goes through an example of this here: http://dynamicsuniversity.com/steps-to-send-emails-to-custom-email-address-text-field-from-a-workflow/
You can write custom workflow or you should go for plugin development.
You will get details for it on below blogs.
For custom-workflow
https://msdn.microsoft.com/en-us/library/gg334455.aspx
Blog:-
https://lakshmanindian.wordpress.com/2012/10/14/custom-workflow-activity-in-microsoft-dynamics-crm-2011/
more knowledge on your email sending requirement.
https://social.microsoft.com/Forums/en-US/375f5dad-0382-4112-ab0d-5b42ba235d96/crm-2011-workflow-sending-email-problem?forum=crmdevelopment

Implementing a two-way communication between Microsoft Dynamics CRM and 3rd party app

I need to implement a bi-directional communication between Microsoft Dynamics CRM and a 3rd party server. The ideal scenario is as follows:
User tries to create an entity in CRM
In pre-create hook a 3rd party library function is called (or web service or whatever), filled with relevant info, which tries to create the respective entity on the server
If the call fails, creation fails in CRM
If the call succeeds, the entity is created in the CRM AND additional fields are filled with return values from the call
More specifically, I want to do something like this when user tries to create a new entity instance:
try {
ExternalWebService.CreateTrade(ref TradeInfo info)
//this was initialized on the external server
myCRM_Trade_Entity.SerialNo = info.SerialNo;
CreateNew(myCRM_Trade_Entity);
} catch (whatever) {
fail;
}
What would be the suggested way to do this? I am new to Dynamics, have read about Workflows and Plugins but am not sure how should I do this properly.
The way to do that is obviously a plugin, except if the process called by the web service is very long and could timeout.
The only way to avoid creating an entity, is to create a plugin and hook it on the pre-create event, like you are saying.
When using a workflow, the entity must be saved before the workflow is executed.
I think you are on the good way. I would, however, avoid including a library, the webservice solution should be better, because it does not required to register other libraries before registering the plugin assembly.

Resources