c# - Dynamics CRM SDK: Execute Multiple Requests for Bulk Update of around 5000 Records -


i have written function update default price list active products on crm 2013 online.

//the method takes iorganization service , total number of records created input private void updatemultipleproducts(iorganizationservice service, int batchsize, entitycollection updateproductscollection, guid pricelistguid) {     //to execute request have add microsoft.xrm.sdk of latest sdk reference     executemultiplerequest req = new executemultiplerequest();     req.requests = new organizationrequestcollection();     req.settings = new executemultiplesettings();     req.settings.continueonerror = true;     req.settings.returnresponses = true;     try     {          foreach (var entity in updateproductscollection.entities)         {             updaterequest updaterequest = new updaterequest { target = entity };             entity.attributes["pricelevelid"] = new entityreference("pricelevel", pricelistguid);             req.requests.add(updaterequest);         }         var res = service.execute(req) executemultipleresponse;  //execute collection of requests     }          //if batchsize exceeds 1000 fault thrown.in catch block divide records batchable records , create     catch (faultexception<organizationservicefault> fault)     {         if (fault.detail.errordetails.contains("maxbatchsize"))         {             var allowedbatchsize = convert.toint32(fault.detail.errordetails["maxbatchsize"]);             int remainingcreates = batchsize;              while (remainingcreates > 0)             {                 var recordstocreate = math.min(remainingcreates, allowedbatchsize);                 updatemultipleproducts(service, recordstocreate, updateproductscollection, pricelistguid);                 remainingcreates -= recordstocreate;             }         }     } } 

code description : there around 5000 active product records in system. updating default price list of them using above code.

but, missing here that, has updated 438 records. loops through while statement correctly, not updating of them here.

what should batchsize when run function first time?

any 1 can me here?

thank you,

mittal.

you pass remainingcreates batchsize parameter code never references batchsize going reenter while loop every time.

also, i'm not sure how doing error handling need update catch block doesn't let faultexceptions pass-through if don't contain maxbatchsize value. right now, if take faultexception regarding other batch size ignored.

{     if (fault.detail.errordetails.contains("maxbatchsize"))     {         var allowedbatchsize = convert.toint32(fault.detail.errordetails["maxbatchsize"]);         int remainingcreates = batchsize;          while (remainingcreates > 0)         {             var recordstocreate = math.min(remainingcreates, allowedbatchsize);             updatemultipleproducts(service, recordstocreate, updateproductscollection, pricelistguid);             remainingcreates -= recordstocreate;         }     }     else throw; } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -