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

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.

Related

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

Addressing the customer by their first name in CRM 2011 email templates triggered by Service Activity workflows

If a customer schedules a service activity using my web application and I want to send them an automated confirmation email, it seems I have two options:
Have the workflow create and send a new email message. On this view (see below), you can use fields from related entities on the service activity (e.g. the customer's first name).
Have the workflow use an email template. It seems that email templates do not allow you to access fields from a related entity, like first name, so the only option here is to address the customer by their FULL name.
Are there any solutions that I missed, or am I stuck with the first option if I want to address the customer in a personal, natural way on this automated email?
Unfortunatly, the CRM is pretty limited on that aspect. The best workaround is to add the firstname to the Service Activity entity. May suit you or not. Otherwise, it is achievable through a the SDK, but that's much more complicated if you don't already use it.

CQRS Task UI - Responding to underlying changes

Been moving into some task oriented UI as a part of my CQRS implementation.
The problem is I have come across the need to update additional properties in my UI as a result of a change made by an initial command sent from the same UI.
My case is different but here's an example...
eg. CommandA Add item to cart resulted in the following events (which all need to be reflected on the UI)
change to store inventory
add item to shopping cart
change total with sales tax
What's the best way to handle this without baking my business logic into my UI?
return a list of resulting events that were performed as a result to the initial command?
return a DTO that reflects changes
other ideas?
I haven't completed it yet, but my idea is to use a Hub from the SignalR framework and subscribe to events and act on them. As long as you can correlate user guids with the connected user guids in SignalR, you can send updates to the correct client and even detect if they still are there.
SignalR isn't that mature yet but the tests I have done works pretty good.
I use it with Knockoutjs and I just update my view models and call functions.
Do those events really need to be reflected in the UI? Consider Amazon, who display "you just added foo to your cart", but don't show any of those other details. That might save you from the problem by redefining it away.
Otherwise, why are you afraid of business logic in the "UI" - specifically, why not include some components from the service that owns each part of that system in your client, and give them the responsibility of doing whatever local updates are appropriate?
In other words, having part of the logic from your sales tax service running in the UI is fine. You (obviously) don't trust it with the billing calculations for tax, but you can totally trust it to do the right thing for the client.
The other advantage of that model is that you get instant feedback for the user, or at least the option of showing instant feedback, without baking more business process knowledge into the client.
For example, recalculating shipping takes time to do - if your client shows a spinner over that, something needs to know to trigger that showing up, right?
If your UI knows that, it has embedded business process around the process. On the other hand, if you have code that is part of the "shipping" service, you can change what response occurs in the client by changing only the one service...

Callbacks from MS Dynamics CRM to a webservice

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.

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

Resources