2

Here's the scenario: I have a SP 2013 Visual studio workflow in my Staging Server. I want to replace the current workflow with the updated version. (Not add as a new version, I want to replace it)

What I have in my hand is the visual studio 2012 published WSP file.

Here are the steps that I performed:

  1. Removed workflow association from the list by going the workflow settings page.
  2. Deactivated the 'Content Type feature' (via web interface)
  3. Performed an IISReset
  4. Deactivated the 'Workflow feature' (via web interface)
  5. Performed an IISReset
  6. Uninstalled the 'Content Type feature' (via STSADM commands)
  7. Performed an IISReset
  8. Uninstalled 'Workflow feature' (via STSADM commands)
  9. Performed an IISReset
  10. Retracted and removed the workflow.wsp from the solution management.
  11. Performed an IISReset

Now thinking that the workflow is completely removed, I performed the following steps to add the solution:

  1. Added and Deployed the workflow.wsp in the Solution Management.
  2. Performed an IISReset
  3. Activated the 'Content Type feature' (via web interface)
  4. Performed an IISReset
  5. Activated the 'Workflow feature' (via web interface)
  6. Performed an IISReset
  7. Checked the List Settings > Workflow Settings for the Workflow association. It was fine.

However when I triggered the workflow, I am still getting the old workflow instance which can spotted obviously by the difference in the logic.(Incorrect tasks were getting created)

What am I missing here?

1 Answer 1

1

Found the solution.. Thanks to Thiru Srinivasan's blog. Here's what I did.. I developed a custom web part. See the UI and code below.

Webpart UI

enter image description here

Webpart CS Code

protected void CheckIfWorkflowExistsButton_Click(object sender, EventArgs e)
{

    Guid siteId = SPContext.Current.Site.ID;
    Guid webId = SPContext.Current.Web.ID;

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite(siteId))
        {
            using (SPWeb web = site.OpenWeb(webId))
            {
                web.AllowUnsafeUpdates = true;

                PerformWorkflowDefinitionOperations(web, false);                                    
            }
        }
    });

}

private void PerformWorkflowDefinitionOperations(SPWeb web, bool deleteDefinition)
{

    try
    {
        this.WorkflowExistsLabel.Text = string.Empty;
        this.DeleteResultLabel.Text = string.Empty;

        var workflowServicesManager = new WorkflowServicesManager(web);

        var workflowDeploymentService = workflowServicesManager.GetWorkflowDeploymentService();

        if (!string.IsNullOrEmpty(this.WorkflowDefinitionGUIDTextBox.Text))
        {
            Guid workflowDefinitionId = new Guid(this.WorkflowDefinitionGUIDTextBox.Text);

            var workflowDefinition = workflowDeploymentService.GetDefinition(workflowDefinitionId);

            if (workflowDefinition != null)
            {
                this.WorkflowExistsLabel.Text = "Workflow Found!!";

                if (deleteDefinition)
                {
                    workflowDeploymentService.DeleteDefinition(workflowDefinitionId);
                    this.DeleteResultLabel.Text = "Deleted!";
                }

            }
            else
            {
                this.WorkflowExistsLabel.Text = "Workflow NOT Found!!";
            }
        }
        else
        {
            this.WorkflowExistsLabel.Text = "WF Definition GUID not provided";
        }
    }
    catch (Exception ex)
    {
        this.ExceptionLabel.Text = ex.Message;
        LogULSException(ex);
    }

}

public void LogULSException(Exception ex)
{
    // Trace the issue with the web service in the ULS Logs
    SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;

    diagSvc.WriteTrace(0,
        new SPDiagnosticsCategory("Portal_ULSLogs", TraceSeverity.Monitorable,
            EventSeverity.Error), TraceSeverity.Monitorable, "Message: {0}", ex.Message);

    diagSvc.WriteTrace(0,
        new SPDiagnosticsCategory("Portal_ULSLogs", TraceSeverity.Monitorable,
            EventSeverity.Error), TraceSeverity.Monitorable, "StackTrace: {0}", ex.StackTrace);

    diagSvc.WriteTrace(0,
        new SPDiagnosticsCategory("Portal_ULSLogs", TraceSeverity.Monitorable,
            EventSeverity.Error), TraceSeverity.Monitorable, "Inner Exception: {0}",
            ex.InnerException);
}

protected void DeleteWFDefinitionButton_Click(object sender, EventArgs e)
{
    Guid siteId = SPContext.Current.Site.ID;
    Guid webId = SPContext.Current.Web.ID;

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite site = new SPSite(siteId))
        {
            using (SPWeb web = site.OpenWeb(webId))
            {
                web.AllowUnsafeUpdates = true;

                PerformWorkflowDefinitionOperations(web, true);
            }
        }
    });
}

Update in the Steps.. After the web part was deployed, I again removed the Worfklow association (step 1) and then deleted the definition via this web part and then performed the rest of the steps mentioned above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.