cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

The idea is to prep everything in terms of lists, columns etc. and also the forms. Once deployed changes can still be applied by power users. But the initial setup should go somewhat automatically. Is it possible at all? Or do we need to keep manual steps to do the import of the prepared XML forms?

Labels: (3)
Tags (1)
Reply
10 Replies
Not applicable

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

I seemed to have found something that might work. I'm pretty sure it isn't supported. But this could get you started.

Use a console application.

-> Make sure it is x64 (SharePoint 2013).

Reference a bunch of assemblies including:

  • Nintex.Forms
  • Nintex.Forms.SharePoint
  • Microsoft.SharePoint
  • System.Web

This is the actual code if my POC:

using System;

using Nintex.Forms;

using System.Web.UI.WebControls;

using System.IO;

using Nintex.Forms.SharePoint.Services;

using Microsoft.SharePoint;

using System.Web;

namespace NintexFormDeployment

{

    class Program

    {

        static void Main(string[] args)

        {          

            var fileName = @"C:\Workspaces\LocalOnly\NintexFormDeployment\NintexFormDeployment\Form.xml";

            byte[] fileBytes = File.ReadAllBytes(fileName);

            string formMarkup = NfUtilities.ConvertByteArrayToString(fileBytes);

            Form form = FormsHelper.XmlToObject(formMarkup);          

          

            var webUrl = "<yourweburl>";

            using (SPSite site = new SPSite(webUrl))

            {

                using (SPWeb web = site.OpenWeb())

                {

                    FakeSPContext(web);

                    SPList list = web.Lists["Gemeenten"];

                    string ctId = list.ContentTypes["item"].Id.ToString();

                    Console.WriteLine("Publishing....");

                    var service = new NfWcfService();

                    service.PublishForm(ctId, list.ID.ToString(), form);

                    Console.WriteLine("Done");

                    Console.ReadKey();

                }

            }

        }

        public static SPContext FakeSPContext(SPWeb web)

        {

            // Ensure HttpContext.Current

            if (HttpContext.Current == null)

            {

                HttpRequest request = new HttpRequest("", web.Url, "");

                HttpContext.Current = new HttpContext(request,

                  new HttpResponse(TextWriter.Null));

            }

            // SPContext is based on SPControl.GetContextWeb(), which looks here

            if (HttpContext.Current.Items["HttpHandlerSPWeb"] == null)

                HttpContext.Current.Items["HttpHandlerSPWeb"] = web;

            return SPContext.Current;

        }

     

    }

}

Accept as Solution Reply
Workflow Hero

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

Hi Chris,

I am using above code, however I get error in following line:

string formMarkup = NfUtilities.ConvertByteArrayToString(fileBytes);

Form form = FormsHelper.XmlToObject(formMarkup);

The error message is, the name NfUtilities and FormsHelper is does not exist in current context.

Could you please provide me code for FormsHelper and NfUtilities class?

Or some hint to get me out of this error?

It would be great help for me.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

I could use the code above to reach the same with PowerShell. Thanks a lot!

Yogeshkumar Patel​ have you added the usings for Nintex.Forms and Nintex.Forms.SharePoint.Services?

If you want to do this with PowerShell, don't forget to load the assemblies:

[void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Forms")

[void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Forms.SharePoint")

0 Kudos
Accept as Solution Reply
Not applicable

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

Hi,

Where can I get Nintex.Forms and Nintex.Forms.SharePoint.Services assemblies.

I don't have access to server

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

You need access to the server because the code above can be executed on a server only. It's not client code.

Nonetheless you can get the dlls if you haven't installed nintex on your system by renaming the nintex-setup file (for e.g. NintexForms2013core.exe to NintexForms2013core.cab. Then you can open it with a tool like Total commander to get the .dlls from the included .wsp files.

0 Kudos
Accept as Solution Reply
Highlighted
Not applicable

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

Hi,

I am running this code using .Net client object model.

I am facing below exception at, Nintex.Forms.Form form = FormsHelper.XmlToObject(formMarkup);

Could not load file or assembly 'Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

can you help me how to get rid of this.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

You need to execute your code on the server. The Microsoft.SharePoint.dll is located there.

0 Kudos
Accept as Solution Reply
Not applicable

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

I don't have access to the server, is there any way that we can deploy Nintex form using Client Object model.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Is there a way to deploy a Nintex Form from a script (like powershell or feature) instead of a Export/Import?

So I'm trying to convert this POC in .NET back to Powershell for my project.  I get as far as this:

[void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Forms")
[void][System.Reflection.Assembly]::LoadWithPartialName("Nintex.Forms.SharePoint")

[byte[]]$bytes = Get-Content $filePath -Encoding byte

$list = $web.Lists[$ListName]
$ct = $list.ContentTypes[$ctName]
$ctID = $ct.Id.ToString()
$listID = $list.ID.ToString()
$formMarkup = [Nintex.Forms.NfUtilities]::ConvertByteArrayToString($bytes);
$Form = [Nintex.Forms.FormsHelper]::XmlToObject($formMarkup)
[Nintex.Forms.SharePoint.Services.NfWcfService]:Smiley TongueublishForm($ctID, $listID, $Form);

When I get an error message stating that there is no function PublishForm.  Was wondering if anyone here would be able to shed some light on this as I would think this should be the correct syntax but clearly I'm wrong.

Thanks for any assistance.

0 Kudos
Accept as Solution Reply