Freigeben über


Using Microsoft BizTalk Dynamics CRM Adapter – Part 3

In previous articles, we talked about –

· Installing and configuring BizTalk CRM Adapter

· Basics of CRM System

· How to perform query operation using BizTalk adapter

· How to perform create operation using BizTalk adapter

I suggest you refer my previous articles before reading current one –

Part1: https://blogs.msdn.com/brajens/archive/2007/05/27/using-microsoft-biztalk-dynamics-crm-adapter-part-1.aspx

Part2: https://blogs.msdn.com/brajens/archive/2007/05/30/using-microsoft-biztalk-dynamics-crm-adapter-part-2.aspx

I am going to cover delete operation in current article. The very next article will talk about update operation.

How to perform Delete operation with CRM Adapter

As I mentioned earlier, you can consider a CRM system as sub-systems having information captured in entities. When performing delete operation, we actually delete instance of one the entity.

Since entities are related to each other, it is always good idea to check dependent entities and come up with logic to handle them when performing delete operation.

Perform “Delete Contact Entity” instance using .net code (calling CRM web service)

Let’s talk through an example. I am going to write.net code to delete one instance of entity “contact”.

I added CRM web service as web reference and named it “CRMServer”. Following is code to delete contact instance in CRM system.

CrmServer.CrmService service = new CrmServer.CrmService();

service.Delete(CrmServer.EntityName.contact.ToString(), new Guid("737ddf30-b7f7-4cff-a559-70ce250ee19b"));

Code is two liners. I first created an instance of CRM web service client.

CrmServer.CrmService service = new CrmServer.CrmService();

And then I called delete method. It takes two parameters – name of the entity whose instance it to be deleted and internal unique id (GUID) of the instance.

service.Delete(CrmServer.EntityName.contact.ToString(), new Guid("737ddf30-b7f7-4cff-a559-70ce250ee19b"));

Every entity instance has a unique primary key value (GUID) inside CRM system. You just need to pass this guid and entity name.

Perform “Delete Contact Entity” instance using BizTalk orchestration (using Dynamics CRM Adapter)

I am going to perform same delete operation using BizTalk CRM adapter. I am not going to take things in very detail because reader’s who have read my previous articles have enough background about it. I will primarily talk about entity, action to be selected and schemas to be used for messaging with CRM system.

· To delete a contact, we need a solicit-response send port (say “CRMSendPort”) which can talk to CRM system using BizTalk CRM adapter.

· Create a BizTalk project.

· We have to generate schema for delete operation. When you generate schema, select action as “Delete” and entity as “contact”.

· It generates lots of schemas and one BizTalk orchestration file. Open orchestration file and delete all port types and multi-part message types generated by default. These are useful but I am asking to clean them so that you can create and understand things from scratch.

· Out of generated schemas, we are interested in two schemas only – one request schema (to send details of contact to be deleted) and one response schema.

· “contact_Entities.xsd” serves purpose of request schema. There are two nodes/fields which are required to set – one is “contactid” and other is “crm_action”. Supply internal primary key value (GUID) to “contactid” element (same way we did in .net code above). Then supply “delete” as value for “crm_action” field.

Note: Whenever, you want to delete instance of any entity, it generates a schema with name “ <entity_name> _Entities.xsd”. And this schema is used to form request message.

· Response is handled by “Respond.xsd” schema which can be found @ “C:\Program Files\BizTalkAdapter\Schemas” depending upon adapter installation location. You have to include this Response.xsd in project.

· We are now all set to implement logic. Create two messages of type request and response schemas. Hook these messages to a static solicit-response send logical port using send and receive shape. Use map (with transform shape) or message assignment shapes to create request xml and send it via solicit-response port. When response comes consume it as per requirement.

· When you are done with coding, compile project and deploy it. After deployment, bind solicit-response orchestration ports with physical solicit-response port (“CRMSendPort”) created in above steps. Enlist and start orchestration. Finally trigger orchestration to test delete operation.

· That’s it.

Conclusion

We have quickly seen delete operation. I am writing these small segregated articles to check one operation at a time. Update operation is lot similar to create operation and we will go through it in very next article.

Comments

  • Anonymous
    April 03, 2009
    Here are a great series of articles on integrating BizTalk Server with Dynamics CRM: 1. Using Microsoft