Using Microsoft BizTalk Dynamics CRM Adapter – Part 4
We talked about create, delete, query and configuration details in previous articles. In current article, I am quickly going to summarize update operation with CRM system.
I suggest you refer my previous articles before reading current one. This will provide you complete context of things.
Next article in this series will be a final one in which I will talk about dealing with special attributes like (pick list, lookup etc.) and custom attributes/entities.
How to perform “Update” operation with CRM System
“Update” operation is lot similar to “Create” operation. Only difference is that you supply internal primary key (GUID) of entity instance along with other attributes to be modified. Internal primary key is used to identify entity instance in CRM system.
When updating an entity instance, keep in mind that you cannot provide blank or null values for a required attribute. Another point is that you just need to send values of those attributes only which you wish to update.
Perform “Update Contact Entity” instance using .net code (calling CRM web service)
I am going to write a sample code which will update some of the attributes (in this case “lastname”) of an existing contact entity instance.
I added CRM web service as web reference and named it “CRMServer”. Following is code to update contact instance in CRM system.
CrmServer.CrmService service = new CrmServer.CrmService();
CrmServer.contact contact = new CrmServer.contact();
CrmServer.Key contactKey = new CrmServer.Key();
contactKey.Value = new Guid("7e1120f8-2b15-4fc4-a347-59a702725c61");
contact.contactid = contactKey;
contact.lastname = "Marks";
service.Update(contact);
I first created an instance of CRM web service client.
CrmServer.CrmService service = new CrmServer.CrmService();
Then I created instance of contact entity and supplied internal primary key value (GUID) for “contactid” attribute. “contactid” attribute of contact entity holds primary key value of entity instance.
CrmServer.contact contact = new CrmServer.contact();
CrmServer.Key contactKey = new CrmServer.Key();
contactKey.Value = new Guid("7e1120f8-2b15-4fc4-a347-59a702725c61");
contact.contactid = contactKey;
Then I am supplying value for attributes which I wish to update. In this case, it is “lastname”.
contact.lastname = "Marks";
Finally, I called update method, passing contact object into it.
service.Update(contact);
Perform “Update Contact Entity” instance using BizTalk orchestration (using Dynamics CRM Adapter)
It is time to perform the same operation using BizTalk CRM adapter. I will quickly summarize things because reader’s who have read my previous articles have enough background about other details. I will primarily talk about entity, action to be selected and schemas to be used for messaging with CRM system.
· To update 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 update operation. When you generate schema, select action as “Update” and entity as “contact”.
· It generates lots of schemas and one BizTalk orchestration file in project. 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.
· We are interested in two schemas only – one request schema (to send details of contact to be updated) and one response schema.
· “contact_Entities.xsd” serves purpose of request schema. In our example, we need to set following fields/elements –
o “contactid” – it holds primary internal id (GUID) of contact to be updated
o “lastname” – supply updated last name value for contact
o “crm_action” – we can keep it blank because we have already supplied value of primary key and this instructs adapter to search for contact entity instance and perform update operation. But it is always good practice to provide action name. In this case, we supply “update” as “crm_action” value.
· 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 update operation.
· That’s it.
Conclusion
You must have realized that “create” and “update” are very similar. Only difference is that for create, we don’t supply primary key value while it is must to provide in case of update operation. We are close to our journey. In next article, I will talk about special attributes and custom entities/attributes. Thanks for reading.
Comments
- Anonymous
June 30, 2007
We talked about create, delete, query and configuration details in previous articles. In current article - Anonymous
July 15, 2007
Thanks Brajendra.. Articals really helped me to get started with the integration.I am waiting for your next article on dealing with PickList, and Lookup.Our project has Integration between 2 CRMS. synchronization among them. these CRMS have been customized.Any help is really appreciated.hariomhari@gmail.com - Anonymous
July 16, 2007
Hi Brajendra,Your articles have helped to get started with Integration.Thanks a lot.m eagerly waiting for your next articles on PickLists and Lookups.Our project needs to Integrate 2 CRMS(Syncronization).Any help in this regard is really appreciated.Hari. - Anonymous
April 03, 2009
Here are a great series of articles on integrating BizTalk Server with Dynamics CRM: 1. Using Microsoft