Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

Posted on by Microsoft Employee

Hi,

I want to perform conditional updates on the CRM database. For this, I want to perform Create-Update and Update-Delete in a single transaction so that if anything goes wrong with the any request, everything will be rollback.

I am aware of Rollback. But my question here is on the executing a single transaction with multiple request ex. one with CreateRequest and 2nd with UpdateRequest. Can we execute these requests in a single transaction?

Something like below code:

var transReq = new ExecuteTransactionRequest()
{
    // Create an empty organization request collection.
    Requests = new OrganizationRequestCollection(),
    ReturnResponses = true
};

var account = new Account()
{
    Name = "Acme, Inc."
};

var createReq = new CreateRequest
{
    Target = account
};

transReq.Requests.Add(createReq);

account.NumberOfEmployees = 100;

var updateReq = new UpdateRequest
{
    Target = account
};

transReq.Requests.Add(updateReq);

var response = (ExecuteTransactionResponse)svc.Execute(transReq);


Any thoughts or ideas to achieve this?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    That helped. Thank you.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    It's not recommended because crm is using sql guid generation.. some kind of optimization is happening there.. other than that, it should work. I don't think you can do it any other way since you will need to get that good for the update/delete, and you won't be able to. Can only assign it in advance.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    Yes I saw that but there was a comment you have added not recommended so I thought to ask a little different approach in my question, to try with different entity. Would you please go through that comment and let me know if it is possible, please.

    Thank you,

    Pratik Soni.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    Think I just explained it above..

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    Yes Sir, in this case yes it is having a problem. Because 2nd request will not be able to fetch the ID created in request 1. But is there any way that we can even execute transaction in 2 different entities?

    i.e. req1 will be Create request on Account entity while req2 will update the existing record of Contact entity.

    If yes that we can do it... then can you please let me know how to do that?

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    Sorry.. I get it now.. if you create a record and want to update it after.. try setting the Id in your code..

    Account.id = Guid.NewGuid()

    Not recommended, in general, but should work.  

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    Is there a problem with your code? Looms like it should do exactly that - execute both requests in the same transaction

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    Sorry if my question is misleading. Please have a look for updated question for better understanding.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    ExecuteTransactionRequest will execute all requests in the same transaction. If one request fails, all others will be rolled back

    ExecuteMultipleRequest will execute each request in its own transaction, so there is no rollback for all requests. If one request fails, what happens after depends on what you pass to the ContinueOnError parameter

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Different request types (Create-Update, Update-Delete) in single ExecuteTransactionRequest or ExecuteMultipleRequest

    Sure Gulcan, I am aware of Rollback. But my question here is on the executing a single transaction with multiple request ex. one with CreateRequest and 2nd with UpdateRequest. Can we execute these requests in a single transaction?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans