Moving records to another workflow

There are two ways to move records from one workflow to another. Both methods preserve tracking information held in the progress tables and displayed on the tracking screen. Changes made to the data such as completing tasks, sending mail merges, or sending emails are also preserved. You manage both methods using an ASP page called with a global or transition rule.

  1. Reset the workflow. You can create a rule attached to the entry state that lets a user reset the workflow. This is useful if you've two valid workflows for an entity and a user progresses along the wrong workflow. In this case, the user must cancel the connection to the workflow and restart at the beginning of the alternative workflow. The code in the ASP page blanks out or nulls the record's workflowid field.
    Copy
    var intRecordId = CRM.GetContextInfo("case","case_caseid");
    var myRecord = CRM.FindRecord("case","case_caseid="+intRecordId);
    myRecord.case_workflowid = null;
    myRecord.SaveChanges();
    Response.Redirect(CRM.URL(281));
  2. Jumping to another workflow. You can switch from one workflow directly into another workflow and join the new workflow at a particular stage. To do this, you must create a new workflowinstance record and link it to the workflowstate information and the record that must switch to the new workflow.
    Copy
    var intRecordId = CRM.GetContextInfo("case","case_caseid");
    var myRecord = CRM.FindRecord("case","case_caseid="+intRecordId);
    var wkinRecord = CRM.CreateRecord("workflowinstance");
    wkinRecord.wkin_workflowid = 7; // This is the workflow id of the alternate case workflow;
    wkinRecord.wkin_currententityid = 3; // this is the id of the case table found in the custom_table meta data table
    wkinRecord.wkin_currentrecordid = intRecordId; // The ID of the Case record being workflowed;
    wkinRecord.wkin_currentstateid = 27; // This is the id value of the state found in the workflowstate table.
    wkinRecord.SaveChanges();
    myRecord.case_workflowid = wkinRecord.wkin_instanceid; // This sets the Case as belonging to the new workflow.
    myRecord.SaveChanges();
    Response.Redirect(CRM.URL(281));