Showing posts with label Nintex Workflow 2010. Show all posts
Showing posts with label Nintex Workflow 2010. Show all posts
13

Import and Publish Nintex Workflows programmatically

I recently developed a SharePoint solution which requires that 3 Nintex 2010 workflows are published on 13 document libraries in 22 SharePoint sites. I developed the Nintex workflows on a single library in one site and gave it to the test team to perform quality assurance. Now that I know the workflows are working well, we are ready to export them and upload and publish them to a much larger test environment. This will require that we import and publish 3 workflows x 13 libraries x 22 sites …thus a repetitive 858 manual tasks… there is no way that we will do this manually, so I took a little time to develop a tool which will programmatically import and publish workflows.
I found that it really is easy to utilise the Nintex web services to manage workflows.
In this tutorial I will give you a high level overview of how to use code to upload / import .nwf files to a target SharePoint site thereby automating the process as much as possible. This approach will help you to move workflows between development-, test- and production environments.
What we want to achieve:
I developed a simple tool which allows you to select one or more exported workflow files as source and then specify the target environment to which the workflows must be imported and published.
image



You need the following:
1. A few working Nintex workflows exported to local .nwf files.
2. A target SharePoint site with document libraries or lists which you can use as target to import and publish the workflows to.
3. Nintex Web Services must be accessible (installed with Nintex).
Preparation:
1. .NWF Files: To create a few workflows to test with I created a few really simple workflows like the one below which just update a single field on the list / library. I then saved the workflow, published it and tested it. After I have confirmation that the workflow works well I proceeded to export the workflow as a local .nwf file. Remember that this must be done in a SharePoint site which is different than your target site or you have to delete the workflows from the site before you test the import code.
image





2. Target SharePoint site: Your target SharePoint site must have Nintex Workflow installed and configured. You can go to your test target library and from the ribbon verify that you have access to create or manage Nintex workflows:
image


3. Nintex Web Services: You should be able to browse to the Nintex Workflow web services.
These web services are included as part of the Nintex Workflow out of the box installation.
The URL will be <SP Web App URL></_vti_bin/nintexworkflow/workflow.asmx>
Example: My target site is in the following web application http://ltp-21:17819/ so the URL which I will use to access the Nintex Workflow web services will be:
http://ltp-21:17819/_vti_bin/nintexworkflow/workflow.asmx
You should be able to use Internet Explorer to navigate to the web service URL.

Let’s Write the Code:
Please note that in order to simplify the tutorial I will only show the code which is required to import and publish the workflows.
I therefore assume that you will be able to develop the additional code which you will need to make a tool similar to the screenshot at the beginning of this post fully functional. If you are interested in any other bits of the code for the complete tool please leave a comment and I will gladly send it to you.
1. Create a new Visual Studio Windows Forms Application.
2. Because we target SharePoint 2010 remember to set your platform target to 64 bit:
image
3. Add a web service reference to the Nintex Workflow web service:
Remember the URL of the Nintex Workflow web service is in the form
<SP Web App URL></_vti_bin/nintexworkflow/workflow.asmx>
Example: My target site is in the following web application http://ltp-21:17819/ so the URL which I will use to access the Nintex Workflow web services will be:
http://ltp-21:17819/_vti_bin/nintexworkflow/workflow.asmx
I used NintexWorkflowService as the web reference name
image
4. Add a new button named cmdImportWorkflow onto Form1:
image
5. Add the following code to the button click event:

try
{
NintexWorkflowService.NintexWorkflowWS objWFService = new NintexWorkflowService.NintexWorkflowWS();
objWFService.Url = "http://ltp-21:17819/MyNintexSite/_vti_bin/nintexworkflow/workflow.asmx";
objWFService.Credentials = System.Net.CredentialCache.DefaultCredentials;
byte[] arrWorkflowFile = System.IO.File.ReadAllBytes(@"E:\WorkflowsToImport\UpdateTitlewithTime.nwf");
objWFService.PublishFromNWF(arrWorkflowFile, "MyDocs", "My Imported Workflow", true);
}
catch (Exception exception)
{
MessageBox.Show("An error occured while trying to publish the workflows: " + exception.Message);
}
MessageBox.Show("Done");
Let’s Analyse the code:
1. Instantiate the Nintex Workflows web method:
NintexWorkflowService.NintexWorkflowWS objWFService = new NintexWorkflowService.NintexWorkflowWS();
2. Ensure the web method will execute against the correct target URL:
objWFService.Url = "http://ltp-21:17819/MyNintexSite/_vti_bin/nintexworkflow/workflow.asmx";
This URL must be the full URL to the target SharePoint site followed by “/_vti_bin/nintexworkflow/workflow.asmx”.
Please ensure that you replace the first part of the URL with that of your target environment.
3. Set the credentials for the web service:
objWFService.Credentials = System.Net.CredentialCache.DefaultCredentials;
4. Read the Nintex workflow file (.nwf) into a byte array:
byte[] arrWorkflowFile = System.IO.File.ReadAllBytes(@"E:\WorkflowsToImport\UpdateTitlewithTime.nwf");
This is the workflow which we exported earlier to a local file.
5. Call the web method to import and publish the workflow file.
objWFService.PublishFromNWF(arrWorkflowFile, "MyDocs", "My Imported Workflow", true);
The parameters are:
1. arrWorkflowFile: Byte Array of the workflow file to be imported.
2. listName: The name of the target list / library.
3. workflowName: The name which will be assigned to the new imported workflow.
4. saveIfCannotPublish: Flag to indicate whether the workflow must be saved if it cannot be published.

Verify Success:
Run the code and step through each line to ensure there are no exceptions.
After successful execution open the target SharePoint site and the target document library / list.
Go to Manage Nintex Workflows and verify that the workflow was successfully imported and published – you should see the new published workflow.
image
Conclusion:
As you can see from the sample code it is really easy to automate the import and publishing of Nintex 2010 workflows to SharePoint 2010. You might come across a few exceptions if your environment does not allow certain workflow actions or if dependencies (like list or field lookups in workflows) are not in place in the target environment.
You can now use the very basic sample code to develop a tool like the one I illustrate at the top of this post to automate workflow upload & publishing and hopefully save your system administrator hours of manual configuration.
Enjoy !!

109

Nintex Workflow 2010 ‘Task Reminder’ Bug & Fix

This morning I came across the following error while trying to publish a Nintex 2010 workflow which contains a ‘Task Reminder’ workflow action.


Background:
I have a SharePoint 2010 MOSS environment. I create a new Nintex 2010 Workflow which I can save and publish without problems.


Then I add a ‘Task Reminder’ action

image


And when I publish the workflow I get the following error:

image

Cause:
For a type to be used within the workflow, it must be registered as an Authorized Type in the web.config file. All of the Nintex workflow actions and custom types are registered as authorized types.
Some of the workflow actions have a property of a type that inherits from a generic list, that is List<T>. List<T> is a basic system type provided in .NET.
With SharePoint 2010, List<T> is no longer authorized. Workflow actions that use a type that inherits from List<T> no longer run or publish.
The SharePoint web service to validate workflows returns the following error when publishing:
<Error><CompilerError Line="0" Column="0" Text="Type System.Collections.Generic.List`1, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 is not marked as authorized in the application configuration file." /></Error>

Work around:
Add the following to the web.config of the SharePoint web application on which you want to publish the workflow.

<authorizedType Assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" Namespace="System.Collections.Generic" TypeName="List`1" Authorized="True" />

Save the web.config and return to SharePoint and now you will be able to successfully publish the same workflow (containing the Task Reminder):

12

Nintex Workflow 2010 Installation

Today I installed and configured Nintex Workflow 2010 for SharePoint 2010.

I must say, the guys at Nintex are doing a brilliant job and their product documentation is clear and easy to follow.
I had absolutely no problems installing Nintex Workflow 2010 on my SharePoint 2010 sandbox and this tutorial will show how easy it is to prepare a Nintex Workflow 2010 environment.

The reasons for choosing Nintex Workflow 2010 as a workflow designer tool deserve a separate post, but for a quick overview please have a look at this site.

Prerequisites:
In my environment I had the following in place before installing Nintex Workflow 2010:
  * Windows 2008 Server
  * Microsoft Office SharePoint Server 2010
  * SQL Server 2008 (and other prerequisites to run SharePoint 2010)
  * SMTP Server (outside of the SharePoint Farm)
  * SMTP Service configured on Windows 2008 server (see instructions)
  * Outgoing email settings configured for SharePoint Farm (see instructions)
  * Outgoing email settings configured for SharePoint Web App (see instructions)

Installation & Configuration:
The install is very simple.
I followed the installation guide which is available on this site under technical information.

The following steps need to be followed:
  1 Install the Nintex Workflow 2010 solution package
  2 Perform Database Configuration
  3 Configure Workflow Server Settings
  4 Activate Features

1 Install the Nintex Workflow 2010 (NW2010) solution package:
To install the NW2010 solution package is really very easy.
Ensure that you are logged in to the server as local admin.

  1.1 Run the NintexWorkflow2010.msi from the local machine.
        Follow the steps through the wizard until finished.
 
I got a error during installation complaining that the assembly failed in the zone "My Computer"
To solve this make sure that User Account Control is turned off or set it to the very minimum.
Follow these steps:
  1.Click on Start, and then Control Panel
  2.In Control Panel, click User Accounts
  3.In the User Accounts window, click User Accounts
  4.In the User Accounts tasks window, turn the User Account Control to the very minimum
  5.Restart to apply the changes



  1.2 Deploy the solution to web applications.
       Open the SharePoint 2010 Central Administration 
       go to 'System Settings' and then to 'Manage Farm Solutions'
       You will see 2 new solutions in the list of solutions in the farm.
       They are:
         nintexworkflow2010.wsp and
         nintexworkflow2010enterprisefeatures.wsp
       Deploy both solutions to all content web applications.
       After both solutions have been deployed successfully you should see the following 
       status:

       In order to activate the NW2010 configuration functionality in Central Admin, you
       have to deploy the nintexworkflow2010enterprisefeatures.wsp solution again, but
       this time select only the Central Admin web application as the "Deploy To" location.
       It is not necessary to retract the solution first, just deploy it again.
   1.3 The next step is to import the Nintex License.
       If you return to the Home page of Central Admin you will notice a new configuration
       section called "Nintex Workflow Management". 
      Click on 'Nintex Workflow Management' and select 'Licensing'


      From here you can click on the 'Import' button... to import your license file.


Ok, once this is all done we are ready to:
2- Configure the Nintex database.
In Central Admin go to the Nintex Workflow Management section.
Click on the "Database Setup" link and then click on the "Create" button.
Provide details of your database server and click on the "OK" button to allow the database to be generated.
The cool thing here is that in previous versions of Nintex Workflow (for SharePoint 2007) it was really tricky to get the database connection details working in a single server installation. It seems like it has all been taken care of since I am able to use my Windows Authentication to access the database without any problems.

Great, we are moving ahead... the next step is to:
3 - Configure the Nintex Workflow 2010 Server Settings
This will require that we:
    3.1 Perform Web Application Activation
    3.2 Enable Workflow Actions
    3.3 Configure Email Settings
    3.4 Enable and Configure Lazy Approval
   
    3.1 Perform Web Application Activation:
          In Central Admin go to the 'Nintex Workflow Management' section and click on
          "web application activation"
          Activate the feature to the applicable web application.
         
    3.2 Enable Workflow Actions
          In Central Admin go to the 'Nintex Workflow Management' section and click on

          "manage allowed actions"
          Select the workflow actions which you want to allow in your farm and click on OK.
         
    3.3 Configure Email Settings
          In Central Admin go to the 'Nintex Workflow Management' section and click on

          "Global settings"
          Provide the appropriate smtp server settings and click on "OK"

3.4 Enable and Configure Lazy Approval
         In Central Admin go to the 'Nintex Workflow Management' section and click on

         "LazyApproval Settings"
         Click on the "Enable / Disable LazyApproval" shortcut to enable LazyApproval.


The last step is to:
4 - Activate Features
Go to the Site Collection Features of your site on which you want to use Nintex Workflow 2010. (In SP2010 it is located under "Site Settings" --> Site Collection Features under Site Collection Administration)
You will see the following new site collection features.
Enable all of them:

Go to the Site Features of your site on which you want to use Nintex Workflow 2010. (In SP2010 it is located under "Site Settings" --> Manage site features under Site Actions)
Congratulations, Nintex Workflow 2010 have now been installed and configured and you can begin building workflow solutions !!!

In my next post I will show how to build a simple workflow to test whether the installation was successful.

Enjoy !!

You will see the following new site features.
Enable all of them: