Is it possible to import a workflow from a File system directory?

  • 25 August 2015
  • 1 reply
  • 9 views

Userlevel 3
Badge +8

I've seen some articles on using a workflow to publish a Nintex workflow and also publishing directly from a SharePoint site to another site but nothing on how to take an NWF file sitting in a directory on the server and using powershell to add the workflow to the site or to a specified list. Is this possible?

Thanks!


1 reply

Userlevel 3
Badge +8

It is definitely possible.

I set up a variable named $WFPathRoot which contains a different path depending on what environment I'm executing in. I have a solution called ePayment which has specific workflows that are relevant to it. I put those in their own directory. I use a foreach loop to go through the nwf files in that directory and add them. One snafu I experience is that because the workflow doesn't retain constants when being exported the workflow doesn't publish. But it does add it and my workflow team takes care of resolving the issues that are preventing it from publishing. Hopefully this can help someone else.

$FolderName = "ePayment"

$WFPathRoot = $WFPathRoot + $FolderName

Write-Host "Getting Workflows in $WFPathRoot for ePayment`n"

$files = ([System.IO.DirectoryInfo] (Get-Item $WFPathRoot)).GetFiles()

$WebSrvUrl = $WebURL+"/_vti_bin/nintexworkflow/workflow.asmx"

$proxy = New-WebServiceProxy -Uri $WebSrvUrl -UseDefaultCredential

$proxy.URL = $WebSrvUrl

foreach($file in $files)

{   

  #Add file

    $WorkflowFile = $WFPathRoot  + """ + $File.Name   

  $NWFcontent = get-content $WorkflowFile

  $List = $spweb.Lists[$FolderName];

  $wfTitle = $File.Name -replace ".nwf", ""

  Write-Host "Adding $wfTitle"

  $Results =  $proxy.PublishFromNWFXml($NWFcontent, $List.Title ,$wfTitle, $true)

  if($Results -eq ""){

  Write-Host "`n$File.NameAdded"}else{

   Write-Host "`npublished"

}}}

Reply