locked
Quick question about CRM 4 System Jobs. RRS feed

  • Question

  •  

    I have written windows app to migrate data from external databases into a new instance of CRM 4.

     

    I recently discovered that I could use the CRM Web Services to empty all the entities during testing, a lot quicker than clearing the data out by hand.  My method creates Bulk Delete System Jobs.

     

    What I am doing now is kicking them off and going to CRM to check the progress.  They take a while to complete.

     

    My question is, does the bulk delete only delete records which exist in CRM at the time the jobs are kicked off?  That is, could I wait a minute or two and then kick off my import, knowing that the "in progress" Bulk Delete is not going to delete any new imported data?

     

    Regards,

    Gordon

    Thursday, January 8, 2009 9:30 AM

Answers

  • You are correct.  I don't think I understood the code properly.  As always a new day reveals that the Delete Bulk Job code begins with a query so presumably it will generate a list of records somewhere or mark the records in the quesry for deletion -  and then delete only those. Any new records added after the query has run (irrespective of how long a gap there is between completing the query segment and acrually commencing the deletions) should not be deleted.

     

    I suppose I was looking for reassurance that CRM isn't being lazy and just deleting all the records in the entity.

     

    In some ways, when basing code on a code sample, it is ofter better if that code sample doesn't work out of the box as the developer actually has to read and understand it rather than simply pasting it in and going, "Hey that works!".

     

    Thanks for your help.  I'm sure someone can correct me if my assumptions above are wrong.

     

    G

    Friday, January 9, 2009 10:35 AM

All replies

  • You could wait for the system job to complete by polling its state every few seconds.

     

    //ImportJobId is the Guid of the import system job

    ColumnSet cols = new ColumnSet();
    cols.Attributes = new string[] { "statecode" };

     

    for (int i = 0; i < 50; i++)
    {

    System.Threading.Thread.Sleep(2000);

    asyncoperation op = (asyncoperation)service.Retrieve(EntityName.asyncoperation.ToString(), ImportJobId, cols);

    if (op.statecode.Value == AsyncOperationState.Completed)
    {
              //Start Bulk Delete Job

    break;

    }
     

    Hope this helps.

     

    Friday, January 9, 2009 1:44 AM
  • This might be a very stupid question from me, but did you search for an answer for this? I seem to recall a blog post on one of the "named" CRM blogs that explains how to set parameters into the bulk delete feature. So you could use any combination of those to get to your test data - created on date, owner, etc.
    Friday, January 9, 2009 8:29 AM
  • You are correct.  I don't think I understood the code properly.  As always a new day reveals that the Delete Bulk Job code begins with a query so presumably it will generate a list of records somewhere or mark the records in the quesry for deletion -  and then delete only those. Any new records added after the query has run (irrespective of how long a gap there is between completing the query segment and acrually commencing the deletions) should not be deleted.

     

    I suppose I was looking for reassurance that CRM isn't being lazy and just deleting all the records in the entity.

     

    In some ways, when basing code on a code sample, it is ofter better if that code sample doesn't work out of the box as the developer actually has to read and understand it rather than simply pasting it in and going, "Hey that works!".

     

    Thanks for your help.  I'm sure someone can correct me if my assumptions above are wrong.

     

    G

    Friday, January 9, 2009 10:35 AM
  • Yes, that's right the bulk delete job will only delete records returned in the query result set. 

     

    So you have to wait for the records to be created in order to have them returned in the query result set that you use for the bulk deletion job.

     

    Otherwise your bulk deletion job query returns nothing or some of the desired results and your deletion job might not delete all of the test data.

     

    If you are developing and testing a custom application that's importing a large amount of records (say 20,000+) you don't want to manually delete all those records each time. So you wait until the import job is completed and then remove all of your test data.

     

    Note: You could have your query for your bulk deletion job return all the records created by your import job.

    Monday, January 19, 2009 12:40 AM