locked
Retrieve Entityid in fault exception while doing bulk update RRS feed

  • Question

  • Hi,

       I am very much new to crm 2011 services. I am trying to do bulk update on an entity. I want to know the entity id in fault. For service settings i have set OnErrorContinue=true and ReturnResponse=false. I am getting the fault response but not the entity id. Even while trying to set ResponseName I am getting runtime error. 

    Thanks in advance.

    Ketan Mehta

    Tuesday, March 19, 2013 5:40 AM

Answers

  • Hi Ketan,
    "slow down code execution" for what you described is exaggerated. Starting from you example of 1000 requests and suppose half will fail, if  you set the property "ReturnResponses" to false the "Responses" collection will only contain the fault objects so you can avoid also the check if the Fault property is different from null.
    After to get the ID you need only to access the value of an array already loaded in memory.
    Also if you find a way to extend the ExtensionData for your purpose, you will move the computational cost (for retrieving the fault IDs) from a point to another point in your code.


    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Thursday, April 18, 2013 8:00 AM
    • Marked as answer by ketanMaheta Thursday, April 18, 2013 12:54 PM
    Thursday, April 18, 2013 8:00 AM

All replies

  • Hi ketan,

    Can u pls kindly explain me using wat coding ur trying to perform bluk update of records??

    • Proposed as answer by meenakshi Patnala Tuesday, March 19, 2013 6:36 AM
    • Unproposed as answer by ketanMaheta Thursday, April 18, 2013 6:08 AM
    Tuesday, March 19, 2013 6:35 AM
  • HI,

    If u want to have a bluk update we can u a tool for bulk update of records.

    http://blogs.msdn.com/b/dynamicscrmonline/archive/2010/06/23/bulk-update-data-in-crm-online.aspx

    http://blog.xrm.com/index.php/2011/06/edit-multiple-records-part-1-microsoft-dynamics-crm-2011/

    Pls go through the following link it might be help full.

    If so please "mark as answer" and vote as "helpful post".


    Tuesday, March 19, 2013 6:40 AM
  • Hi,

       I am using C# and crm 2011 services.

       I am using ExecuteMultipleRequest and ExecuteMultipleResponse as below.

         foreach (var entity in ResultList.Entities)
           {
                  UpdateRequest updateRequest = new UpdateRequest { Target = entity };
                  updateRequest.RequestId = entity.Id;
                  requestWithResults.Requests.Add(updateRequest);
           }

           responseWithResults = (ExecuteMultipleResponse)service.Execute(requestWithResults);

         Now in responseWithResults i am getting fault but the response object is null.

    I hope this info will be sufficient.

    Thanks,

       Ketan Mehta

    Tuesday, March 19, 2013 1:02 PM
  • Hi Ketan

    Did you try to enclose your code in a try catch block. Use a FaultException before generic exception like this.

     catch (FaultException faultEx)
        {
          Console.WriteLine("An unknown exception was received. " 
            + faultEx.Message
            + faultEx.StackTrace
          );
         
        }

    Also, did you try appending entity.Id in the exception custom message. This will give you the detail of the record getting exception. 

    Tuesday, March 19, 2013 3:50 PM
  • Hi,

       I am already using catch (FaultException<OrganizationServiceFault> fault). I am able to read the fault also but not able to get the entity id for which the exception occurred. Since I am doing bulk update in each batch I have 1000 record updates requests. As well as i am setting the RequestId while doing bulk request as below.

    foreach (var entity in ResultList.Entities)
     {
         UpdateRequest updateRequest = new UpdateRequest { Target = entity };
         updateRequest.RequestId = entity.Id;
         requestWithResults.Requests.Add(updateRequest);
      }

      responseWithResults = (ExecuteMultipleResponse)service.Execute(requestWithResults);


    Thanks,

    Ketan Mehta

    Wednesday, March 20, 2013 7:31 AM
  • Did you try appending request id in faultexception message

    foreach (var entity in ResultList.Entities)
     {
    
    try{
    
         UpdateRequest updateRequest = new UpdateRequest { Target = entity };
         updateRequest.RequestId = entity.Id;
         requestWithResults.Requests.Add(updateRequest);
      }
    
     catch (FaultException faultEx)
        {
          Console.WriteLine("An unknown exception was received. " 
            + faultEx.Message
            + faultEx.StackTrace
             + "Record Id is " + entity.Id.toString()  
          );     
        }
    }

    Wednesday, March 20, 2013 7:36 AM
  • Hi,

      I am doing a BULK update. In your code where are you executing the bulk requests??? Once I have the requestWithResult object build than only i will do bulk update. So how the entity.Id will available in catch statement? Moreover, I my case the responseWithResult itself has the fault collection so catch statement won't help.... Please refer my code..

    Wednesday, March 20, 2013 10:15 AM
  • Ketan

    This is an update request, so entity.Id should be available even before you send the request to update a record.

    In create however, the entity.Id will be missing till you get the successful response.

    That's the same reason why, in your code, you are able to assign entity.Id to updateRequest.RequestId.

    I think that is where you are missing ...

    In line updateRequest.RequestId, RequestId is Gets or sets the ID of an asynchronous operation (system job). Optional.  (inherited from OrganizationRequest).

    While you are trying to assign updateRequest.RequestId = entity.Id where entity.Id is id of entity and not id of async operation.

    http://msdn.microsoft.com/en-in/library/microsoft.xrm.sdk.messages.updaterequest_members.aspx

    RequestId is optional. So comment the line and try to execute your code. If you are debugging the code, then it will give you better insight.

    Wednesday, March 20, 2013 1:55 PM
  • Hi,

       I am not getting you :). Please refer http://msdn.microsoft.com/en-in/library/jj863631.aspx.  I have referred this in my coding. 

       Please guide how to accommodate the your suggestions. 

    Thanks,

    Ketan 

    • Marked as answer by ketanMaheta Friday, March 22, 2013 4:55 AM
    • Unmarked as answer by ketanMaheta Thursday, April 18, 2013 5:59 AM
    Thursday, March 21, 2013 12:40 PM
  • Hi Ketan,
    you need to use the RequestIndex property from ExecuteMultipleResponseItem to retrieve the IDs, after you have the index you can retrieve the value from the request collection that you executed.
    I just wrote a post in my blog with an example:

    CRM Answers - Retrieve fault entity IDs when performing ExecuteMultiple

    My blog: www.crmanswers.net


    • Proposed as answer by Guido PreiteMVP Thursday, March 21, 2013 1:55 PM
    • Edited by Guido PreiteMVP Thursday, March 21, 2013 1:57 PM
    • Marked as answer by ketanMaheta Thursday, April 18, 2013 5:59 AM
    • Unmarked as answer by ketanMaheta Thursday, April 18, 2013 5:59 AM
    • Unproposed as answer by ketanMaheta Thursday, April 18, 2013 6:06 AM
    • Proposed as answer by Guido PreiteMVP Thursday, April 18, 2013 8:00 AM
    Thursday, March 21, 2013 1:52 PM
  • Hi Guido Preitee,

        Thanks for your valuable reply. This is what i was looking for. Additionally I have another question. 

        To reduce the response size I have already set ReturnResponse=false. In this case I am getting only faults from service.  While doing association, if association already exists, it will return fault like duplication. I don't want service to return to me.... Is there anything I can set in multiple request to achieve?

    Thanks,

    Ketan

    • Marked as answer by ketanMaheta Thursday, April 18, 2013 5:59 AM
    • Unmarked as answer by ketanMaheta Thursday, April 18, 2013 5:59 AM
    Friday, March 22, 2013 4:55 AM
  • Hi Ketan,
    as you wrote the ExecuteMultiple will returns at least the faults also if you set ReturnResponse = false, can't set to don't return faults at all.
    If inside the logic of your application you don't need to take care of faults when associate just don't consider the response.
    In case you are doing mixed request inside the same ExecuteMultiple (for example 1 update and 1 associate) you need to check the exception message, but maybe is more easy to do different ExecuteMultiple for the different request types.

    btw, can you please mark answered my previous post? thanks



    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Friday, March 22, 2013 8:18 AM
    • Unproposed as answer by ketanMaheta Thursday, April 18, 2013 6:08 AM
    • Proposed as answer by Guido PreiteMVP Thursday, April 18, 2013 8:00 AM
    Friday, March 22, 2013 8:18 AM
  • Hi Guido Preite,

         I agree on your answer but when it comes to performance scaling, I have an issue.

         Actually I am doing batch bulk request and each batch holds max of 1000 requests and the total update request as a whole operation may be more than 100000 request. Now I if follow your instruction, each time for any faults in a batch request, I need to take off the request from request object as you mentioned but it will slow down code execution. 

    There another way to cope up this issue. Use of ExtentionData class available for all types of requests but I m not getting a proper example on net. By using this property we can get the same input from response, provided in request. If you have any idea on this please share.

    Thanks,

    Ketan Mehta

           

    Thursday, April 18, 2013 6:06 AM
  • Hi Ketan,
    "slow down code execution" for what you described is exaggerated. Starting from you example of 1000 requests and suppose half will fail, if  you set the property "ReturnResponses" to false the "Responses" collection will only contain the fault objects so you can avoid also the check if the Fault property is different from null.
    After to get the ID you need only to access the value of an array already loaded in memory.
    Also if you find a way to extend the ExtensionData for your purpose, you will move the computational cost (for retrieving the fault IDs) from a point to another point in your code.


    My blog: www.crmanswers.net

    • Proposed as answer by Guido PreiteMVP Thursday, April 18, 2013 8:00 AM
    • Marked as answer by ketanMaheta Thursday, April 18, 2013 12:54 PM
    Thursday, April 18, 2013 8:00 AM