Automatiser les déploiements Nintex Workflow et Nintex forms


Lors de la mise en oeuvre d’un récent projet utilisant les technologies Nintex, l’ensemble des déploiement ont été automatisés.

Voici, ci dessous, un descriptif des commandes utilisées. Chaque commande doit être exécutée dans l’invite de commande powershell SharePoint avec un compte admin SharePoint et Nintex.

Pré requis : Nintex workflows et Nintex forms doivent être déployés au niveau de la ferme ainsi que sur la webapp ciblée. L'export des workflows (fichier NWF) et des formulaires (fichier XML) se fait via le fonctionnement natif proposé par Nintex

Ce développement a été réalisé en grande partie par Alain Pilikian, Consultant SharePoint chez iNext.

Activer Nintex Niveau WebApp

Ce code remplace l’activation via l’admin centrale :

$WebAppUrl = "http://yourWebApp"
$WebApp = Get-SPWebApplication $WebAppUrl
[System.Reflection.Assembly]::LoadWithPartialName("Nintex.Workflow.AdministrationPages") >> $null
$manageSafeAction = New-Object Nintex.Workflow.AdministrationPages.ManageSafeActions
$installWebAppMethod = $manageSafeAction.GetType().GetMethod("InstallWebApp",[Reflection.BindingFlags]::NonPublic -bor [Reflection.BindingFlags]::Instance)
$installWebAppMethod.Invoke($manageSafeAction, $WebApp)

Ce code permet d’activer la feature Nintex Forms niveau webapp :

$NintexFormsWebApplicationFeatureID = "0cdf436f-61b0-43d2-b250-4360f0353b63"
Enable-SPFeature $NintexFormsWebApplicationFeatureID -Url http://yourWebApp

 

Activer Nintex Niveau Collection de Site

Ce code permet d’activer la feature NintexFormsSitePrerequisites niveau siteCol :

$NintexFormsSitePrerequisitesFeatureID = "716f0ee9-e2b0-41f0-a73c-47ed73f135de"
Enable-SPFeature $NintexFormsSitePrerequisitesFeatureID -Url http://yourSiteCol

Ce code permet d’activer la feature NintexFormsListSite niveau siteCol :

$NintexFormsListSiteFeatureID = "202afc3c-7384-4700-978d-6da3d3cce192"
Enable-SPFeature $NintexFormsListSiteFeatureID -Url http://yourSiteCol

Ce code permet d’activer la feature NintexWorkflow niveau siteCol :

$NintexWorkflowFeatureID = "0561D315-D5DB-4736-929E-26DA142812C5"
Enable-SPFeature $NintexWorkflowFeatureID -Url http://yourSiteCol

Ce code permet d’activer la feature NintexFormsWorkflowSite niveau siteCol :

$NintexFormsWorkflowSiteFeatureID = "ac8addc7-7252-4136-8dcb-9887a277ae2c"
Enable-SPFeature $NintexFormsWorkflowSiteFeatureID  -Url http://yourSiteCol

Ce code permet d’activer la feature NintexWorkflowWebParts niveau siteCol :

$NintexWorkflowWebPartsFeatureID = "EB657559-BE37-4b91-A369-1C201183C779"
Enable-SPFeature $NintexWorkflowWebPartsFeatureID -Url http://yourSiteCol

Activer Nintex Niveau Site

Ce code permet d’activer la feature NintexFormsAdminWeb niveau site :

$NintexFormsAdminWebFeatureID = "70f4f7da-4fb4-4e30-ba1a-a733efb2e1ac"
Enable-SPFeature $NintexFormsAdminWebFeatureID -Url http://yourSiteCol/sitename

Ce code permet d’activer la feature NintexWorkflowWeb niveau site :

$NintexWorkflowWebFeatureID = "9BF7BF98-5660-498a-9399-BC656A61ED5D"
Enable-SPFeature $NintexWorkflowWebFeatureID -Url http://yourSiteCol/sitename

Déployer un workflow Nintex

Utilisation de NWAdmin.exe directement intégré à l’invite de commande powershell SharePoint.

Ce code permet déployer un workflow au niveau d’un site :

$WorkflowName = "The name of your workflows"
$WorkflowFile = "path of the nwf"
$SiteUrl = "http://yourSiteCol/sitename"
NWAdmin.exe -o DeployWorkflow -workflowName $WorkflowName -nwfFile $WorkflowFile -siteUrl $SiteUrl -saveIfCannotPublish -overwrite

Ce code permet de déployer un workflow au niveau d’une liste :

$WorkflowName = "The name of your workflows"
$WorkflowFile = "path of the nwf"
$SiteUrl = "http://yourSiteCol/sitename"
$TargetList = "YourListTitle"
NWAdmin.exe -o DeployWorkflow -workflowName $WorkflowName -nwfFile $WorkflowFile -siteUrl $SiteUrl -targetList $TargetList -saveIfCannotPublish -overwrite

Déployer un formulaire Nintex

Ce code permet de déployer un formulaire Nintex au niveau d’une liste :


function Get-FormDigest(
	[Microsoft.SharePoint.SPWeb] $Web
)
{
	Write-Host ">> Getting Form Digest ..."

	[System.Reflection.Assembly]::LoadWithPartialName("System.IO") >> $null

	$formDigestRequest = [Microsoft.SharePoint.Utilities.SPUtility]::ConcatUrls($Web.Site.RootWeb.Url, "_api/contextinfo")

	Write-Host ">> Form Digest url is: $formDigestRequest"

	$formDigestUri = New-Object System.Uri($formDigestRequest)

    $credCache = New-Object System.Net.CredentialCache
    $credCache.Add($formDigestUri, "NTLM", [System.Net.CredentialCache]::DefaultNetworkCredentials)
    $spRequest = [System.Net.HttpWebRequest] [System.Net.HttpWebRequest]::Create($formDigestRequest)
    $spRequest.Credentials = $credCache
    $spRequest.Method = "POST"
    $spRequest.Accept = "application/json;odata=verbose"
    $spRequest.ContentLength = 0

    [System.Net.HttpWebResponse] $endpointResponse = [System.Net.HttpWebResponse] $spRequest.GetResponse()
	[System.IO.Stream]$postStream = $endpointResponse.GetResponseStream()
    [System.IO.StreamReader] $postReader = New-Object System.IO.StreamReader($postStream)
    $results = $postReader.ReadToEnd()

    $postReader.Close()
    $postStream.Close()

	#Get the FormDigest Value
    $startTag = "FormDigestValue"
    $endTag = "LibraryVersion"
    $startTagIndex = $results.IndexOf($startTag) + 1
    $endTagIndex = $results.IndexOf($endTag, $startTagIndex)
    [string] $newFormDigest = $null
    if (($startTagIndex -ge 0) -and  ($endTagIndex -gt $startTagIndex))
    {
        $newFormDigest = $results.Substring($startTagIndex + $startTag.Length + 2, $endTagIndex - $startTagIndex - $startTag.Length - 5)
    }

	Write-Host ">> Form Digest Set"

	return $newFormDigest
}

function GetJsonFormFromXml($FileName){
	Write-Host ">> Getting Json from Nintex Form Xml ..."

	[System.Reflection.Assembly]::LoadWithPartialName("Nintex.Forms.SharePoint") >> $null
	[System.Reflection.Assembly]::LoadWithPartialName("Nintex.Forms") >> $null
	
	[byte[]] $fileBytes = Read-FileBytes -FileName $FileName
	try
	{
		$form = [Nintex.Forms.FormsHelper]::XmlToObject([Nintex.Forms.NFUtilities]::ConvertByteArrayToString($fileBytes))
	}
	catch [Exception]
	{
		$form = [Nintex.Forms.FormsHelper]::XmlToObject([Nintex.Forms.NFUtilities]::ConvertByteArrayToString($fileBytes, [System.Text.Encoding]::UTF8))
	}

	$form.LiveSettings.Url = ""
	$form.LiveSettings.ShortUrl = ""
	$form.RefreshLayoutDisplayNames()
	$form.Id = [guid]::NewGuid()

	$json = [Nintex.Forms.FormsHelper]::ObjectToJson($form)

	Write-Host ">> Json from Nintex Form Xml is set"

	return $json
}

function Get-SPListByInternalName($Web, $InternalName)
{
	#RootFolder == internal listname, loop through and find (null will be returned if its not found)
	$list = $Web.Lists | Where { $_.RootFolder.Name.ToLowerInvariant() -eq $InternalName.ToLowerInvariant()}
	
	return $list
}

$webUrl = "http://yourSiteCol/sitename"
$Web = Get-SPWeb -site $webUrl
$FileName = "pathtothexmlfile"
$ListRootFolderName= "listRootfoldername"
$NintexAdministratorUsername ="Admin"
$NintexAdministratorPassword ="pwd"
$NintexAdministratorDomain ="domain"

	$formDigest = Get-FormDigest -Web $Web
	$addressUrl = [Microsoft.SharePoint.Utilities.SPUtility]::ConcatUrls($Web.Url, "_vti_bin/NintexFormsServices/NfRestService.svc/PublishForm")
	$addressUri = New-Object System.Uri($addressUrl)

	# Create the web request
    [System.Net.HttpWebRequest] $request = [System.Net.WebRequest]::Create($addressUri)

    # Add authentication to request
	$request.Credentials = New-Object System.Net.NetworkCredential($NintexAdministratorUsername, $NintexAdministratorPassword, $NintexAdministratorDomain)

    # Set type to POST
    $request.Method = "POST";
    $request.ContentType = "application/json; charset=utf-8";
	$request.Accept = "application/json, text/javascript, */*; q=0.01"
    $request.Headers.Add("X-RequestDigest", $formDigest);
	$request.Headers.Add("X-Requested-With", "XMLHttpRequest")

	$form = GetJsonFormFromXml -FileName $FileName

    # Create the data we want to send
	$list = Get-SPListByInternalName -Web $Web -InternalName $ListRootFolderName
	$id = "{$($list.ID)}"
    $data = "{`"contentTypeId`": `"`", `"listId`": `"$id`", `"form`": $form }"

    # Create a byte array of the data we want to send
	$utf8 = New-Object System.Text.UTF8Encoding
    [byte[]] $byteData = $utf8.GetBytes($data.ToString())

    # Set the content length in the request headers
    $request.ContentLength = $byteData.Length;

    # Write data
    try {
		$postStream = $request.GetRequestStream()
        $postStream.Write($byteData, 0, $byteData.Length);
    }
	finally {
		if($postStream) { $postStream.Dispose() }
	}

    # Get response
    try {
		[System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse()

		# Get the response stream
        [System.IO.StreamReader] $reader = New-Object System.IO.StreamReader($response.GetResponseStream())

        try {
			$strResult = $reader.ReadToEnd()
			$jsonResult = ConvertFrom-Json $strResult
			Write-Host ">> Published Nintex Form on List <$ListRootFolderName>" -ForegroundColor Green
			Write-Host ">> Published Version is : $($jsonResult.PublishFormResult.Version)"
		}
		catch [Exception] {
			Write-Host ">> Warning: Unable to get version fron Publish Form Result." -ForegroundColor Yellow
			Write-Host ">> Form Publishing could have failed." -ForegroundColor Yellow
			Write-Host ">> PublishFormResult is : $($strResult)"
		}
	}
    finally {
		if($response) { $response.Dispose() }
	}

Déployer des constantes

Ce code permet déployer des constantes associées à un workflow :

$TargetFile  = "path of the xml"
$SiteUrl = "http://yourSiteCol/sitename"
NWAdmin.exe -o ImportWorkflowConstants -siteUrl $SiteUrl -inputFile $TargetFile -handleExisting Overwrite -includeSite
Publicités

2 réflexions au sujet de « Automatiser les déploiements Nintex Workflow et Nintex forms »

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s