积极答复者
我用BulkDeleteRequest 删除一批记录,CRM会异步执行删除操作,请问怎么查询删除的状态,查看是否完成?

问题
答案
-
CrmService service = CrmLogin.Instance.CrmService; // Query for bulk delete operation and check for status QueryByAttribute bulkQuery = new QueryByAttribute(); bulkQuery.ColumnSet = new AllColumns(); bulkQuery.EntityName = EntityName.bulkdeleteoperation.ToString(); // NOTE: When the bulk delete operation was submitted, the GUID that was returned // was the asyncoperationid, not the bulkdeleteoperationid. bulkQuery.Attributes = new string[] { "asyncoperationid" }; //bulkQuery.Values = new object[1]; bulkQuery.Values = new string[] { JobId.ToString() }; // With only the asyncoperationid at this point, a RetrieveMultiple is required to get the // bulk delete operation created above. BusinessEntityCollection entityCollection = service.RetrieveMultiple(bulkQuery); bulkdeleteoperation createdBulkDeleteOperation = null; // Make sure the async operation was retrieved if (entityCollection.BusinessEntities.Length > 0) { // Grab the one bulk operation that has been created createdBulkDeleteOperation = (bulkdeleteoperation)entityCollection.BusinessEntities[0]; // Check the operation's state if (createdBulkDeleteOperation != null) { if (createdBulkDeleteOperation.statecode.Value != BulkDeleteOperationState.Completed) { // This will happen if it took longer than the polling time allowed // for this operation to compete success = false; } else { success = true; } } }
- 已标记为答案 十三少 2010年2月1日 2:30
全部回复
-
CrmService service = CrmLogin.Instance.CrmService; // Query for bulk delete operation and check for status QueryByAttribute bulkQuery = new QueryByAttribute(); bulkQuery.ColumnSet = new AllColumns(); bulkQuery.EntityName = EntityName.bulkdeleteoperation.ToString(); // NOTE: When the bulk delete operation was submitted, the GUID that was returned // was the asyncoperationid, not the bulkdeleteoperationid. bulkQuery.Attributes = new string[] { "asyncoperationid" }; //bulkQuery.Values = new object[1]; bulkQuery.Values = new string[] { JobId.ToString() }; // With only the asyncoperationid at this point, a RetrieveMultiple is required to get the // bulk delete operation created above. BusinessEntityCollection entityCollection = service.RetrieveMultiple(bulkQuery); bulkdeleteoperation createdBulkDeleteOperation = null; // Make sure the async operation was retrieved if (entityCollection.BusinessEntities.Length > 0) { // Grab the one bulk operation that has been created createdBulkDeleteOperation = (bulkdeleteoperation)entityCollection.BusinessEntities[0]; // Check the operation's state if (createdBulkDeleteOperation != null) { if (createdBulkDeleteOperation.statecode.Value != BulkDeleteOperationState.Completed) { // This will happen if it took longer than the polling time allowed // for this operation to compete success = false; } else { success = true; } } }
- 已标记为答案 十三少 2010年2月1日 2:30