Export and publish a form with the Nintex Forms Web Service API
This topic describes how to export and publish a form with the Nintex Forms Web Service API.
Export a form
In this walkthrough, you will retrieve a Nintex form from SharePoint and save into a folder on your local machine. Nintex Forms provides a set of REST methods in the NfRestService service, which you can use to can retrieve, publish, and delete Nintex Forms from SharePoint lists and document libraries. This walkthrough demonstrates using the Nintex Forms Publish Form Example in the SDK.
To export a form
- Get the SharePoint List ID for the source.
- Set up the project in Visual Studio.
- Build the NintexFormsClient.
-
Modify and Build the PublishFormExample.
-
Review the form XML.
Get the SharePoint List ID for the source
You will need the listID of the SharePoint list that contains the form. You can find the listID with the following steps these steps:
- Open SharePoint, navigate to the list, click Edit , and then click List in the toolbar.
- Click List Settings in the ribbon, and then copy the URL in your browser address bar.
- Find the string after List= . The string should look something like this: %7B9D5F2138%2DC9E6%2D4473%2DA094%2DD7F4284C0388%7D.
- Remove the %7B from the start of the string and %7D from the end of the string. The result is the ListID, that is, 9D5F2138-C9E6-4473-A094-D7F4284C0388.
Set up the project in Visual Studio
Download the code sample from the migration scenario in the Nintex Forms 2013 SDK. 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 process of authentication to SharePoint. The other project, PublishFormExample, contains methods for grabbing a form from the SharePoint list, moving the form from one location to another, publishing a form, or deleting a form. In this walkthrough, you will download the form XML using the NfRestService service.
For the sample download link and overview of the sample, see Using the NintexFormsPublishExample sample
Build the NintexFormsClient
The PublishFormExample console application depends on the NintexFormsClient to handle authentication. So before you get started, build the NintexFormsClient so that you can add the NintexFormsClient.dll in the next step as a reference in the PublishFormExample .
Modify and Build the PublishFormExample
Next, open the PublishFormExample. First, add the NintexFormsClient.dll as a resource.
Since you will use the
GetFormFromSourceAndSaveToFile(); method in the Main() method for this walkthrough, comment out the calls to the methods you're 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.
}
Add your 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.
You can 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, you have a single form and leave it blank.
- Pathname
Pathname where you 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);
}
Build the console application, and then executed it. The application grabs the form XML and saves to your target location.
Review the Form XML
Find the form XML in the location you specified, and open it in a text or XML editor.
Publish the Form controls
Update the console application by adding the target list ID, and to execute the publish to List.
Comment out the GetFormFromSourceAndSaveToFile() form the Main() method in the console application. Remove the comment form the GetFormFromFileAndPublishToSourceList() method in the Main() method.
Verify the variable for the sourceListId is set to the list ID of your target in the GetFormFromFileAndPublishToSourceList() method.
In SharePoint, open the list to verify that it has been published to the target list.
Migrate Forms with the Nintex Forms Web Service API
Publish a Form Using the Nintex Forms On Prem 2013 Web Service