views:

133

answers:

1

I need to implement a bi-directional communication between Microsoft Dynamics CRM and a 3rd party server. The ideal scenario is as follows:

  1. User tries to create an entity in CRM
  2. 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
  3. If the call fails, creation fails in CRM
  4. 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.

+2  A: 

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.

Mercure Integration
I looked into plugins but from what I see there is no way I can get the feedback info other than success/failure. The trouble is the primary key for the entity must be created in 3rd party server so I must update the entity with the value I receive from web service execution. Is there a way to do this through plugin?
CxDoo
When the plugin is registered, the Pre-Create event is fired before the entity is actually created in CRM, and you have access to the complete entity image. So you can call the webservice and modify this image or throw an exception that will avoid the creation of the entity.
Mercure Integration
Thanks! This is what I needed someone to confirm.
CxDoo