Upsert Method – CRM 2015 Update 1

No comments

Hi,

There is a new method named Upsert is introduced which will come handy when we are working data.

Upsert = Update or Insert.

This reduces the complexity of data operation. In situations we may not know that we should update or insert as we are not sure.

By using Upsert method,

 UpsertRequest request = new UpsertRequest() { Target = account };
 UpsertResponse response = (UpsertResponse)service.Execute(request);

Understanding the Upsert process

The following steps describe the processing logic when an UpsertRequest is received:

  1. Send UpsertRequest with enough data for a create or insert operation.
  2. CRM will look up the record targeted by the target entity.
  3. If the record already exists,
    1. Set the ID property of the target entity with the ID of the found record.
    2. Call Update.
    3. Set the RecordCreated to false
    4. Create an EntityReference from the target entity of the update as the value for Target
    5. Return the UpsertResponse
  4. If the record does not exist
    1. Copy any alternate key values into the target entity attributes.
    2. Call Create.
    3. Set the RecordCreated to true
    4. Create an EntityReference from the target entity type and the ID result of the Create request as the value for Target.
    5. Return the UpsertResponse

    For more information: http://www.kingswaysoft.com/blog/2015/04/16/New-CRM-SDK-Feature—Upsert

    Thank you,

    Sreeni Pavalla

Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.