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

答案

  •  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
    2010年1月31日 13:06

全部回复

  •  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
    2010年1月31日 13:06
  • thanks 小宁
    2010年2月1日 2:31