locked
[CRM 4.0]Temporarily disable workflow using SDK? RRS feed

  • Question

  • Hi, I couldn't find this in the SDK help file.

    I have built  a console application that is scheduled to run each night and synchronizes data from a source database to the target CRM database. This is done by executing some StoredProcedures (one for each entity in CRM) and then mapping each line in the SP to a DynamicEntity object en create/update it. One of the SP's contains over 40.000 records.

    The problem is, there is a huge workflow wiht many steps and checks on other entities on the entity with the large SP, so this workflow is fired over 40.000 times. This causes 100% cpu load (caused by the async service process) for many hours after the synchronization process has finished (even up to 20 hours on a not-so-fast server..). Also the asyncoperation and workflowlog tables in the database become very large (I counted 3.3 million workflow entries after a few days of testing..)

    So, back to my question ;)
    Is it possible to disable the workflow using SDK code? Then I could disable the huge workflow when the application starts and enable it again when the application finishes.



    Thursday, October 8, 2009 8:05 AM

Answers

  • Hi, Hanno.

    Yes - this can be done via SDK. Check this url about SetStateWorkflow message.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by Hanno Z Thursday, October 8, 2009 8:56 AM
    Thursday, October 8, 2009 8:12 AM
    Moderator
  • check this url
    http://msdn.microsoft.com/en-us/library/bb890234.aspx

    // Create a request.

    SetStateWorkflowRequest request = new SetStateWorkflowRequest();

    // Assign the request the ID of the workflow to Draft.

    request.WorkflowId = new Guid("b050f053-6968-dc11-bb3a-0003ffbad37a");

    // Set the state to "Draft".

    request.WorkflowState = WorkflowState.Draft;

    // Set the status to its default value.

    request.WorkflowStatus = -1;

    // Execute the request.

    service.Execute(request);

    • Marked as answer by Hanno Z Thursday, October 8, 2009 8:56 AM
    Thursday, October 8, 2009 8:14 AM

All replies

  • Hi, Hanno.

    Yes - this can be done via SDK. Check this url about SetStateWorkflow message.
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by Hanno Z Thursday, October 8, 2009 8:56 AM
    Thursday, October 8, 2009 8:12 AM
    Moderator
  • check this url
    http://msdn.microsoft.com/en-us/library/bb890234.aspx

    // Create a request.

    SetStateWorkflowRequest request = new SetStateWorkflowRequest();

    // Assign the request the ID of the workflow to Draft.

    request.WorkflowId = new Guid("b050f053-6968-dc11-bb3a-0003ffbad37a");

    // Set the state to "Draft".

    request.WorkflowState = WorkflowState.Draft;

    // Set the status to its default value.

    request.WorkflowStatus = -1;

    // Execute the request.

    service.Execute(request);

    • Marked as answer by Hanno Z Thursday, October 8, 2009 8:56 AM
    Thursday, October 8, 2009 8:14 AM
  • Ok thanks, I found the WorkflowState already, but I didn't realize that setting it to Draft would disable the workflow.
    Thursday, October 8, 2009 8:56 AM