SharePoint: Creating Nintex Workflow Constants and Credential Constants


When using Nintex Workflow 2007, you can create constant values at the site and site collection levels which you can reference and use within your own workflows. 

You can create a workflow constant at Site Settings > Manage Workflow Constants > Add Workflow Constant 

Create a workflow constant
Create a workflow constant

 

Creating workflow constants programmatically in code, is somewhat under documented, though it turns to be quite simple; 

public static void CreateWorkflowConstant(string title, string description,
              string value, bool sensitive,
              Guid siteId, Guid webId,
              WorkflowConstant.WorkflowConstantType type, bool adminonly)
{
 var oc = new WorkflowConstant(title, description, value, sensitive,
           siteId, webId, type, adminonly);
 oc.Update();
}

Another great use of Workflow constants is to store security credentials, which you can use to call web services for instance. Workflow constants can be of the following types; 

  • Credential
  • Date
  • Number
  • String

The Credential type has a value which is stored in a particular (string) format, and fortunately there is a Nintex class which you can use for this purpose called CredentialValue. 

public static void CreateCredentialWorkflowConstant(string title, string description,
									CredentialValue cred, bool sensitive,
									Guid siteId, Guid webId, bool adminonly)
{
	if (cred == null) return;

	var serializer = new XmlSerializer(typeof(CredentialValue));
	var sb = new StringBuilder();
	using (var sw = new StringWriter(sb))
	{
		serializer.Serialize(sw, cred);
	}
	var value = sb.ToString();
	CreateWorkflowConstant(title, description, value, sensitive, siteId,
                    webId, WorkflowConstant.WorkflowConstantType.Credential,
                        adminonly);
}

And so to create a new Credential Workflow constant; 

var cred = new CredentialValue("webserviceuser", "password");
WFHelper.CreateCredentialWorkflowConstant("webserviceuser", "Credentials for calling web services",
					cred, false, site.ID, web.ID, true);
New credential Workflow constant
New credential Workflow constant

 

.

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

One thought on “SharePoint: Creating Nintex Workflow Constants and Credential Constants

  1. Great post! Thank you very much. Works great to create new workflow constants and workflow credential constants. Question, do you know if it’s possible to update existing workflow credential constants, specifically the credential value, using PowerShell? I have been able to create new workflow credential constants using PowerShell just fine but can’t figure out how to update existing ones. Sample code below used for creating workflow credential constant in PowerShell:

    [System.Reflection.Assembly]::LoadWithPartialName(‘Nintex.Workflow’) | Out-Null

    # Generate string for Credential
    $cred = New-Object Nintex.Workflow.CredentialValue
    $cred.Username = “username”
    $cred.Password = “password”

    $serialiser = New-Object System.Xml.Serialization.XmlSerializer($cred.GetType())
    $sb = New-Object System.Text.StringBuilder
    $sw = New-Object System.IO.StringWriter($sb)
    $serialiser.Serialize($sw, $cred)
    $Value = $sb.ToString()

    $SiteId = [Guid]::Empty
    $WebId = [Guid]::Empty
    $Name = “Test Credential”
    $Description = “Example Only”
    $Type = “Credential”
    $Sensitive = $true
    $AdminOnly = $false

    Write-Host (“Attempting to create Workflow Constant ” + $Name + ” … “) -NoNewline
    $constant = New-Object Nintex.Workflow.WorkflowConstant($Name, $Description, $Value, $Sensitive, $SiteId, $WebId, $Type, $AdminOnly)
    $constant.Update()
    Write-Host “done”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.