locked
CRM 2011: Transaction RRS feed

  • Question

  • Hello All,

    I am creating some Account through CRM API (OrganisationServiceContext) and then Contact.

    While creating contact if any error occurs I want to roll back - mean remove the account too.

    How this can be achieved, I am using communicating with CRM from a website using Organisation.svc

    Thanks in advance


    Hassan

    Monday, February 24, 2014 5:35 AM

All replies

  • Hello Hassanz,

    I think, CRM 2011 does not support external control of transactions. it does not have calls that will do commit/complete or rollback. Thus, its not compatible with TransactionScope class.

    However, Transactional behavior can be achieved in the following ways.

    • if you submit on request that involve several data operations, then all of these operations will be treated as one atomic transaction.
    • In a plug within the transaction, if you use IOrganizationService Instance that is obtained from IExecutionContext parameter, then any data operations will be in the scope of the original transaction.

    The second point is applicable to you.

    Hope, this will help you out. Feel free to contact in case of query.


    If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.

    Monday, February 24, 2014 5:55 AM
  • You need to switch your logic to plugin to use Transaction or need to write plugin as well so that you could do some validation in plugin when it will be called becase of orgnization service method that you have used if possible.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by Linn Zaw Win Monday, February 24, 2014 3:32 PM
    Monday, February 24, 2014 6:19 AM
    Moderator
  • Guys,

    How about Adding objects in OrganisationServiceContext using AddObject and then links. At the end call SaveChanges. If SaveChanges reaches success then good otherwise all will fail...?

    Please suggest?


    Hassan

    Tuesday, February 25, 2014 1:28 AM
  • Hi Hassanz,

    I have not tried this, but try to use SaveChanges with option none and see if you are able to achieve your requirement.

    HTH


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Tuesday, February 25, 2014 3:11 AM
    Moderator
  • SaveChanges will not wrap all modifications within a transaction. Your only option for transactional control is to make the contact changes within a plugin that fires when the account is created, as per the first reply to this thread. To make this work, you'd need to create fields on the account to receive the data you want to set on the contact.

    The only other possilbility, as you're using accounts and contacts, would be to first create a lead, then use the QualifyLead message to create an account and contact from this. I believe that QualifyLead makes all its changes within a transaction


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Tuesday, February 25, 2014 8:09 AM
    Moderator