mattbriggs

Publish a Form Using the Nintex Forms On Prem 2013 Web Service

Blog Post created by mattbriggs Employee on May 13, 2016

In this example, I will retrieve a Nintex Form from a SharePoint Server and save to a folder on my machine. Nintex Forms provides a set of REST methods in the NfRestService service, which I can retrieve, publish, and delete Nintex forms from SharePoint lists and document libraries. This sample will demonstrate using the Nintex Forms Publish Example in the SDK.

 

Table of Contents

Get the SharePoint List ID for the Source

I will need the listID of the SharePoint list that contains the form I can find the listID with the following steps these steps:

  1. I open SharePoint, navigate to the list, click Edit, and then click List in the toolbar.
  2. In the ribbon, I click Modify, I then copy the URL.
  3. I can either parse the URL, or you cut and paste the URL into this tool to extract the listID:
    http://www.surfpointtech.com/2013/10/14/sharepoint-list-id-and-view-id-calculator/

The listID looks like this:
318a90b7-4ca4-4ed7-9005-f13c4c3d0272

 

Set up the Project in Visual Studio

I download the code sample from the migration scenario in the Form On Prem 2013 SDK. And then I open the sample in Visual Studio. The sample contains two projects. One is the NintexFormsClient and the other is the PublishFormExample. The NintexFormsClient handles the tricky process of authentication to SharePoint. The other project,  PublishFormExample, contains methods for grabbing a form from a SharePoint list, moving the form from one location to another, publishing a form, or deleting a form. In this example, I plan to just download the form XML using the NfRestService service.

 

The sample contains the following structure:

solutionfiles.png

Build the NintexFormsClient

The PublishFormExample console application depends on the NintexFormsClient to handle authentication. So before I get started I build the NintexFormsClient so that I can add the NintexFormsClient.dll in the next step as a reference in the PublishFormExample.

 

Modify and Build the PublishFormExample

Next, I open the PublishFormExample. First, I add the NintexFormsClient.dll as a resource.

Since I'm just going to use the GetFormFromSourceAndSaveToFile(); method in the Main() method for this example, I comment out the calls to the methods I'm not using.

        static void Main()
        {
            // Retrieve the form definition XML from the source environment, and then save
            // the XML to a file for later use.
            GetFormFromSourceAndSaveToFile();

            // Retrieve the form definition XML from the source environment, and then publish
            // the form to the destination environment.
           // GetFormFromSourceAndPublishToDestinationList();

            // Delete the form from the source environment.
           // DeleteFormFromSource();

            // Retrieve the form definition XML from a file, and then publish the form to
            // the source environment.
           // GetFormFromFileAndPublishToSourceList();

            // Pause until the user presses any key.
        }

 

I add my credentials in the NetworkCredentials object. Credentials include username, password, and the domain name.

The method, GetFormFromSourceAndSaveToFile(), will use the listID and grab the form XML for the list it finds there, and then save it a location that you specify. I use the following parameters:

  • listID. Add the listID formatted in the pattern in the example. Note, the application will produce a 400 error if when using the wrong format of the listID.
  • contenttypeID. This is optional and useful if you have more than one Nintex Form stored in your list. In this case, I have a single form and leave it blank.
  • Pathname where I would like to save the file. Remember to include the filename in the pathname, or you will get an error when the application doesn't know what to do with the data.
       private static void GetFormFromSourceAndSaveToFile()
        {
            // Configure the source environment.
            // TODO: Set the SharePoint web URL for the source environment.
            const string sourceUrl = "YourURL";

            // TODO: Set the content type ID of the content type for the source environment.
            // Use an empty string ("") to denote the default content type for the SharePoint list.
            const string sourceContentTypeId = "";

            // TODO: Set the list ID of the SharePoint list for the source environment.
            // Remember to enclose the GUID in curly brackets ({}).
            const string sourceListId = "{318A90B7-4CA4-4ED7-9005-F13C4C3D0272}";

            // Configure the file.
            // TODO: Set the full path and file name to the form definition XML file.
            const string filePath = @"C:\out\FormXML.xml";

            // Create a client context for the source environment.
            var sourceCtx = new NfClientContext(sourceUrl, ClientCredentials, ClientVersion);

            // Get the form from the source environment, and save it to the specified file.
            GetFormFromListAndSaveToFile(sourceCtx, sourceContentTypeId, sourceListId, filePath);
        }

 

I built the console application, and then executed it. The application grabbed the form XML and saved to my target folder.

sucess.png

Review the Form XML

I found the form XML in the location I specified. And that is it!

Outcomes