web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CreateRequest and UpdateRequest

(0) ShareShare
ReportReport
Posted on by 7,316

I am working on insert and update requests to import contacts through a custom application.
I've written createRequest and is working fine for new inserts but I also wnat to do updates in the same code.
So far i've done this for insert but I am not sure how to enforce update request in it. Please suggest how to proceed for updates?

 public override void Input0_ProcessInputRow(Input0Buffer Buffer)
    {
        int index = 0;
        while (Buffer.NextRow())
        {
            _contacts.Add(GetContactFromBuffer(Buffer));
            index++;

            // Let's use buffer size 500. CRM allows up to 1000 requests per single call
            if (index == 500)
            {
                ImportBatch();
                index = 0;
            }
        }
        ImportBatch();
    }

    private void ImportBatch()
    {
        if (_contacts.Count > 0)
        {
            // Create and configure multiple requests operation
            var multipleRequest = new ExecuteMultipleRequest()
            {
                Settings = new ExecuteMultipleSettings()
                {
                    ContinueOnError = true, // Continue, if processing of a single request fails
                    ReturnResponses = true // Return responses so you can get processing results
                },
                Requests = new OrganizationRequestCollection()
            };

            // Build a CreateRequest for each record
            foreach (var contact in _contacts)
            {
                CreateRequest reqCreate = new CreateRequest();
                reqCreate.Target = contact;
                reqCreate.Parameters.Add("SuppressDuplicateDetection", false); // Enable duplicate detection 
                multipleRequest.Requests.Add(reqCreate);
            }

            ExecuteMultipleResponse multipleResponses = (ExecuteMultipleResponse)_orgService.Execute(multipleRequest);

_contacts.Clear();
        }
    }
 
 private Entity GetContactFromBuffer(Input0Buffer Row)
    {
//Insert mappings here
Entity contact = new Entity("contact");
return contact;
}

Thanks for any help.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at
    RE: CreateRequest and UpdateRequest

    In addition to this - you'll also need to specify the 'contactid' attribute for the UpdateRequest target. This could be done by performing a query of CRM first using a surrogate key such as Account Number and use this to return the AcccountID GUID - this is similar to the new Upsert functionality in CRM2015 Update 1 - msdn.microsoft.com/.../dn932135.aspx

    Hope this helps,

    Scott

  • Royal King Profile Picture
    27,686 on at
    RE: CreateRequest and UpdateRequest

    for update use the UpdateRequest with same code what you have already. Where ever you building the contact object make sure you are setting the contact Id attribute in case of update

     foreach (var contact in _contacts)

               {

                   UpdateRequest reqCreate = new UpdateRequest ();

                   reqCreate.Target = contact;

                   reqCreate.Parameters.Add("SuppressDuplicateDetection", false); // Enable duplicate detection

                   multipleRequest.Requests.Add(reqCreate);

               }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans