Skip to content

How to Replace the Built in SharePoint Approval Workflow

We use Nintex Workflow all of the time. It compresses project times, and reduces, if not eliminates the need to develop custom code. One of the problems that we run into though is that the Approval workflow that comes out of the box appears to be hard wired for the SharePoint approval process.

As it turns out, it doesn’t need to be. Christian from iLoveSharePoint has a great solution that lets us replace the built in workflow with a Nintex workflow. It would also work for workflows built with SharePoint Designer. As opposed to rewriting it, I’ll just say that you can link to it here:

http://cglessner.blogspot.com/2009/01/publish-major-version-declarative.html

I will add two things to it. Christian has some sample code that if you just copy and paste won’t work due to wrapping, etc. Here’s what the code should look like:

#workflow must be associated with the target list
$workflowFileName = "Nintex Test.xoml"
$targetListTitle = "MyListName"

function ItemUpdated()
{
    if($item.DisplayName -eq "$($workflowFileName).wfconfig")
    {
        $binFile = $item.File.OpenBinary()
        $wfConfig = [xml][System.Text.Encoding]::UTF8.GetString($binFile)
        $baseId = [Guid]$wfConfig.WorkflowConfig.Template.BaseID

        $library = $web.Lists[$targetListTitle]
        $assoc = $library.WorkflowAssociations.GetAssociationByBaseId($baseId)
        $library.DefaultApprovalWorkflowId = $assoc.Id
        $library.Update()
    }
}

He also mentions one way to get the GUID of the Workflows list. You can also get it by navigating to it with SharePoint Designer, drilling down into your declarative workflow, and opening the workflowname.xoml.wfconfig.xml file, and looking for the DocLibID tag.

One Comment

  1. Joli Joli

    Hi, I have a problem when I add the script to a document library with custom template, the problem is that published the item to a higher version and not the window to start the workflow appears.
    – The powershell script was added successfully
    – The Nintex Workflow Manually starts and does not work when you create or modify

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.