Alternate Keysis also a heavyweight feature associated with system integration. Using this feature can greatly improve the time cost of developing data integration interface and the operation efficiency of the interface.
In previous versions of Dynamics CRM , we could only judge the uniqueness of records through the primary key of the entity, and now we can use Alternate keys to determine the uniqueness of records, and more interestingly, We can configure the entity's Alternate Keyson our own.
Currently alternate key only supports fields of text and number types, and each entity can only configure up to 5 keys, but this is pretty good, and the configuration method is simple:setting–>customization–>entity–> Key
If the data we entered violates the alternate key rule, it will prompt the following error:
The change function has little effect on the end user, but for the vast number of developers as well as the system administrator, its real a very cow x function, with it, since then omitted to spend on the field mapping time. The following code snippet shows how to get a alternate key data and how to use it to replace the entity Primary key
Retrieveentitykeyrequest req1 = new Retrieveentitykeyrequest ();Req1. LogicalName="New_accountkeyforerp";Req1. Entitylogicalname="Account";Retrieveentitykeyresponse REP1 = Crmsvc_online. Execute(req1) as Retrieveentitykeyresponse;String AccountNumber ="2";String AccountName ="Account2";Entity ACC1 = new Entity ("Account");Acc1. Id=guid. Parse("{1b9d2bc3-7a0f-4d94-950a-b367d032092f}");Acc1. Attributes. ADD("AccountNumber", AccountNumber);Acc1. Attributes. ADD("Name", AccountName);Upsertrequest upsertreq1=new upsertrequest ();UpsertReq1. Target=acc1;Crmsvc_online. Execute(UPSERTREQ1);Uses unique key to Update/delete account Keyattributecollection keys=new keyattributecollection ();Keys. ADD("AccountNumber", AccountNumber);Keys. ADD("Name", AccountName);Entity ACC2 = new Entity ("Account", keys);Acc2. Attributes. ADD("Telephone1","1522222222");Crmsvc_online. Update(ACC2);Entity ACC3 = new Entity ("Account", keys);Deleterequest req = new Deleterequest ();Req. Target= New EntityReference ("Account", keys);Crmsvc_online. Execute(req);
If you have a large number of data interfaces involved in your project, try this method to design your program.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Dynamics CRM Update 1 Series (4): Alternate Keys