Recently, we had a client with a requirement to have a new SharePoint Team Site created, and then have a Nintex Workflow automatically provisioned.
There are a few ways to do this – via Nintex itself (!) – or using C# code.
The scenario I was dealing with was :
- Custom/3rd-Party CRM system
- On creation of new customer, need to provision a ‘client site’ in SharePoint
- Deploy the NWF as an artifact – we deployed to _LAYOUTS/Company/MyWF.NWF
- Created a Web Service that did the SharePoint magic
- A few lines of code to provision the workflow
Here’s what you need to do – within a Visual Studio project :
- Add a reference to the Nintex Workflow “web service”
- Can then reference the class/project within C# code (NintexWorkflowWS)
- Read in the contents of the NWF (full XML) – and push/deploy to a list/library
The code steps are as follows…
(1) Add a reference to the Web Service
** NB. uses an SPWeb context – created a few steps earlier
var webServiceUrl = currentWeb.Url;
webServiceUrl += "_vti_bin/nintexworkflow/workflow.asmx";
NintexWorkflowWS wsNW = new NintexWorkflowWS();
wsNW.Url = webServiceUrl;
wsNW.UseDefaultCredentials = true;
(2) Get the contents of the Nintex Workflow (NWF)
var pathNWF = “\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\Company\MyWF.nwf”
//get the Program Files folder
var fileName = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles) + pathNWF;
var contentsNWF = System.IO.File.ReadAllText(fileName);
(3) Deploy the NWF onto the list/library
//call the method to publish the workflow
wsNW.PublishFromNWFXml(nwf, “MyDocLibrary”, “Workflow Title”, true);
That’s essentially it. You just have to call the above method – and it will deploy your workflow.
There’s a bunch of methods within the Nintex Web Service API – the above example uses this method (WSDL) :
There are a bunch of other methods – including “ExportWorkflow” – meaning that you could create a utility/program that cycles through all SPWeb’s – and SPList’s – and then exports to a file.
(I haven’t tried it – I might have to do that next….)
Hope that helps someone – happy Nintex’ing…!