/// <summary> /// Query records and set state /// </summary> /// <param name="q"></param> /// <param name="state"></param> /// <param name="status"></param> /// <param name="batchSize"></param> /// <returns></returns> public CTCRunMultipleResponse BulkSetState(QueryExpression q, OptionSetValue state, OptionSetValue status, int batchSize = 100, CTCBulkTransactionMode transactionMode = CTCBulkTransactionMode.None) { CTCRunMultipleResponse finalResults = new CTCRunMultipleResponse(); finalResults.ResultItems = new List <CTCRunMultipleResponseItem>(); QueryToAction(q, (entityList) => { var requests = new List <OrganizationRequest>(); foreach (var entity in entityList.Entities) { requests.Add(new SetStateRequest() { EntityMoniker = entity.ToEntityReference(), State = state, Status = status }); } var results = RunMultipleRequests(requests, batchSize: batchSize, transactionMode: transactionMode); finalResults.ResultItems.AddRange(results.ResultItems); finalResults.StoppedEarly = results.StoppedEarly; }); return(finalResults); }
/// <summary> /// Query records and run specified workflow for each record /// </summary> /// <param name="q"></param> /// <param name="workflowID"></param> /// <param name="batchSize"></param> /// <returns></returns> public CTCRunMultipleResponse BulkRunWorkflow(QueryExpression q, Guid workflowID, int batchSize = 100, CTCBulkTransactionMode transactionMode = CTCBulkTransactionMode.None) { CTCRunMultipleResponse finalResults = new CTCRunMultipleResponse(); finalResults.ResultItems = new List <CTCRunMultipleResponseItem>(); QueryToAction(q, (entityList) => { var requests = new List <OrganizationRequest>(); foreach (var entity in entityList.Entities) { requests.Add(new ExecuteWorkflowRequest() { WorkflowId = workflowID, EntityId = entity.Id }); } var results = RunMultipleRequests(requests, batchSize: batchSize, transactionMode: transactionMode); finalResults.ResultItems.AddRange(results.ResultItems); finalResults.StoppedEarly = results.StoppedEarly; }); return(finalResults); }
/// <summary> /// Query records, update with data provided in UpdateEntity /// </summary> /// <param name="q"></param> /// <param name="updateEntity"></param> /// <param name="batchSize"></param> /// <returns></returns> public CTCRunMultipleResponse BulkUpdate(QueryExpression q, Entity updateEntity, int batchSize = 500, CTCBulkTransactionMode transactionMode = CTCBulkTransactionMode.None) { CTCRunMultipleResponse finalResults = new CTCRunMultipleResponse(); finalResults.ResultItems = new List <CTCRunMultipleResponseItem>(); QueryToAction(q, (entityList) => { List <Entity> entitiesToUpdate = new List <Entity>(); foreach (var entity in entityList.Entities) { Entity updatedEntity = new Entity(entity.LogicalName); updatedEntity.Id = entity.Id; updatedEntity.Attributes.AddRange(updateEntity.Attributes); entitiesToUpdate.Add(updatedEntity); } var results = BulkUpdate(entitiesToUpdate, batchSize: batchSize, transactionMode: transactionMode); finalResults.ResultItems.AddRange(results.ResultItems); finalResults.StoppedEarly = results.StoppedEarly; }); return(finalResults); }