Dynamics CRM Update1 introduced a heavyweight change to "Upsert Request", believing that friends who have done interfaces have encountered such scenarios when writing data to the CRM because it is not possible to determine whether the data is already present in the CRM system, You need to do a query first and then make subsequent creation or update operations. This kind of data writing process will undoubtedly greatly reduce the performance of data synchronization, because when synchronizing a piece of data, we need to interact with the server two times.
With the launch of the Upsert request, we can say goodbye to the situation, we put the detection logic of the data to the system for processing, the only thing we have to do is to assign the API to the record we want to synchronize, and call the Upsert API. The system will be processed for the records we have passed in: if it is present, it is created, otherwise it is updated. The use of this API is also very simple, you can refer to the following example:
Entity account = new Entity (the "account"); Account. Attributes.Add ("name", String. Format ("{0}-{1}", "Sparta", DateTime.Now.ToLongTimeString ())); Upsertrequest upsertrequest = new Upsertrequest () {Target = account}; Upsertresponse upsertresponse = Crmsvc_online.execute (upsertrequest) as Upsertresponse; if (upsertresponse.recordcreated) {account . Id = upsertResponse.Target.Id; account["name"] = string. Format ("{0}-{1}", "Sparta", DateTime.Now.ToLongTimeString ()); Upsertrequest upsertRequest2 = new Upsertrequest () {Target = account}; Upsertresponse UpsertResponse2 = Crmsvc_online.execute (upsertRequest2) as Upsertresponse; }
Dynamics CRM Update 1 Series (2): Upsert API