Protiviti / SharePoint Blog

SharePoint Blog

May 18
Passing Managed Metadata into a Nintex Workflow via Workflow Variable

Nintex is a wonderful tool. I say that because it is. However, there are times where working with Nintex can lead down a rabbit hole of “why isn’t this possible”.

Recently, we came across a situation where we needed to pass a managed metadata value into a workflow through a workflow start form.  On its own it sounds simple, right?  Well…it required a bit of The Midas Touch.  Nintex workflow start forms don’t pass managed metadata into the workflow itself as a variable.  It’s the only type of column that isn’t supported. 

The workaround for this was to create a text field on the start form and hide it.  JavaScript was written so on submit, it would read the managed metadata column value the user put in, grab the label, and put the label into the hidden text field which was connected to a workflow variable.

Targeting the fields is another hurdle.  There is no reliable way to target a field on a Nintex form without adding a class to the field.  The trick here, is to add a css class through Nintex forms to target with the JavaScript.  Click the container that the field is kept in and add a CSS class at the top.

 

Once that is set, double-click your submit button and under the Advanced tab, in the Client click section, type: return validateOnSubmit();

validateOnSubmit() will be our JavaScript function to copy the label over to the text box for use in the workflow.

 

The JavaScript itself looks like this:

var validateOnSubmit = function () {
    var sourceTarg = NWF$('.targ-tax input');
    var destTarg = NWF$('.dest-tax input');
    var terms = sourceTarg.val();
    /*terms is returned as Label|Guid which can be used to update the value in the workflow. For this project we just needed the GUID as we were looking up to the Taxonomy Hidden List to get the full path of the term. The following splits the terms functions at the bar and returns just the GUID and may not be needed in your code*/
    var term = terms.split('|')[1];
    destTarg.val(term);

    return true;
};

That should go in the Custom JavaScript portion of the form settings of the start form of the workflow.  Remember to return true in the function so the submit button does our fake validation properly.

Go ahead and test it out and Nintex should be able to use the text field as a workflow variable.

Taxonomy Hidden List

As mentioned in the code comment we were also utilizing the Taxonomy Hidden List to get the full path of term by the GUID. If you are not familiar with the Taxonomy Hidden List, it is unsurprising a hidden list that lives on each site collection at /Lists/TaxonomyHiddenList and has some great details about the Managed Metadata Values used in that Site collection. Note: This list only contains values for terms used in the Site Collection and does not contain values for the Term Store as a whole.

In our instance we were using the IDForTerm column to match the GUID (passed in as a workflow variable) to get the Path column. One thing you will probably notice below is there are 3 different columns for Term and Path. The TaxonomyHiddenList will also return any translated value, so if you have a multi-lingual intranet you also view all of the translated values here. In this instance you can see the German values (1031) and the English values (1033). The CatchAllDataLabel can also be used in translated intranet as this field contains all of the translated values for the term in question.

 

Other Uses

We also found this same code snippet to be handy in passing in people values as well. While the Nintex start form allows you to pass in people without an issue. We had an instance where we had to dynamically limit the people picker to a SharePoint group and found that Nintex requires you to specify a group in the workflow variable itself and does not present this option if a Start Form control tied to a variable.

However, by using the Get Query String function and some front end logic we were able to pass in a value through the URL to the Start Form to limit the selection as needed in the start form control. Then using the JavaScript function above pass that value into the workflow variable control.

 

Quick Launch


© Protiviti 2018. All rights reserved.   |   Privacy Policy