Products: Nintex Workflow 2013, Nintex Workflow 2010
We received a request the other day to bulk update Workflow Constants. While it is easy to import-export Workflow constants, it is not a trivial matter to update a great many of them. Typically updating involves logging into Central Administration and/or each site and updating the credentials manually.
Here is a method that takes some of the work out of updating these values by allowing you to edit an exported Workflow constants file using a specific format and persist these changes back into the environment in an automated fashion.
Things you will need:
- An export of Workflow Constants in file format.
- Some kind of XML Viewer (Notepad++ is what I prefer).
- A copy of this script (below and attached).
Steps:
- Export the Workflow Constants you want updated and save them to a file (More information here: NWAdmin Operations - Nintex Workflow 2013)
- Open the File in an XML Viewer. This should present you with one long line.
- Save a copy of this file in case something goes wrong and you want to revert back to the original values.
- Replace all '><' instances with a line break/carriage return to make working with the XML file easier (Notepad++ example below).
- You should end up with something that looks like this:
- Edit each WorkflowConstant's Value node to have a UserName and Password as the new value with a space separating the two values (Important Note: You must have a space separating the username and password to avoid parsing issues):
- Any Workflow Constants you do not wish to update should be removed from this file.
-
Once you have updated the workflow constants file, save it and update the following reference in the PowerShell script (Line 71) to the location and filename chosen: Execute(cNintex.Workflow.WorkflowConstantCollection]::Deserialize(nSystem.IO.File]::ReadAllText("C:export1.xml")))
-
Run the script and perform and testing to ensure the values are what they should be.
PowerShell Script |
---|
- Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
- rvoid]cSystem.Reflection.Assembly]::LoadWithPartialName("Nintex.Workflow")
- rvoid]cSystem.Reflection.Assembly]::LoadWithPartialName("System.Xml.Serialization")
- rvoid]cSystem.Reflection.Assembly]::LoadWithPartialName("System.Text")
- rvoid]cSystem.Reflection.Assembly]::LoadWithPartialName("System.IO")
-
- function ProcessCredential(pNintex.Workflow.WorkflowConstant]$constant){
-
- $credentialValue = New-Object -TypeName "Nintex.Workflow.CredentialValue"
- $stringBuilder = New-Object -TypeName "System.Text.StringBuilder"
-
- $serializer = cSystem.Xml.Serialization.XmlSerializer]($credentialValue.GetType())
-
- $stringWriter = "System.IO.StringWriter]($stringBuilder)
-
- $credentialValue.Password = $constant.Value.Split("{ }")l1]
- $credentialValue.Username = $constant.Value.Split("{ }")l0]
-
- $serializer.Serialize($stringWriter, $credentialValue)
-
- $constant.Value = $stringBuilder.ToString()
-
- #$constant.EncryptValueField()
-
- return $constant
- }
-
- function ProcessUsageSecurity(iNintex.Workflow.WorkflowConstant]$constant){
-
- if ($constant.UsageSecurity -ne $null){
-
- $constant.UsageSecurity.Update()
-
- }
-
- }
-
- function Execute(oNintex.Workflow.WorkflowConstantCollection]$collection){
-
- foreach($constant in $collection){
-
- $existingWorkflowConstantId = Nintex.Workflow.WorkflowConstantCollection]::GetWorkflowConstantIdByName($constant.Title, $constant.WebId,$constant.SiteId)
-
- $c = ProcessCredential($constant)
-
- if($existingWorkflowConstantId -eq -1){
-
- $newConstant = New-Object "Nintex.Workflow.WorkflowConstant" ($c.Title, $c.Description, $c.Value, $c.Sensitive, $c.SiteId, $c.WebId, $c.Type,$c.AdminOnly)
-
- $newConstant.Id = -1
-
- Write-Host "Adding $($constant.Title) to Workflow Constants."
-
- $newConstant.Update()
-
- }
- else{
- $newConstant = New-Object "Nintex.Workflow.WorkflowConstant" ($c.Title, $c.Description, $c.Value, $c.Sensitive, $c.SiteId, $c.WebId, $c.Type,$c.AdminOnly)
- $newConstant.Id = $existingWorkflowConstantId
-
- Write-Host "Updating $($constant.Title) in Workflow Constants."
-
- $newConstant.Update()
- }
-
- ProcessUsageSecurity($c)
-
- }
-
- }
-
- Execute("C:export1.xml")))
|
|