• vadim@workflowexcellence.com
  • Utah, United States

Nintex Forms – Querying User Profiles

A little while ago I discovered some Javascript libraries that I found quite easy to use, called SPAPI.  They let you make web service calls to the SharePoint Web Services from Javascript.

You can download the JS libraries here: Download Libraries

The aim is to have a Nintex Form that on load, pulls out some information from the User Profile of the user that is currently logged into SharePoint, and display that information in the form.  Specifically, the Full name, Phone number and Manager.

Here is what our example User Profile looks like:

User Profile

I’ve manually added a few controls that I will want to update using Javascript, based on information from the web service call.  Here’s what the fom looks like :

Basic Form

Javascript Libraries

When you download the SPAPI Javascript libraries, you have a couple of options.  You can copy the JS files to all your servers (I did this because I only have the one server I’m playing with, and I put them in the LAYOUTS folder).

Ideally, store the JS files in a library, like the Styles Library.  Now you can access those JS files from Nintex Forms.

Once you have the files, you simply make a reference to them in your Nintex Form. You do this, but click on Settings in the form, expand the Advanced section and your JS file paths in the Custom Javascript Includes section.

Javascript Includes

Using the Javascript Libraries

To interact with the controls, I find it easy to store each controls’ ID in a Javascript variable.  You do this, but opening the settings of each control, expand the Advanced section and turn on the “Store Client ID in Javascript variable” and give it a variable name.

Variable ID

The Javascript part of Nintex Forms is found in the Settings of the form, and more specifically in the Custom Javascript section :

Javascript Settings

The Actual Javascript Behind the Form

NWF$(function () {
    function getUserProfileInfo() {
        var lists = new SPAPI_Lists('')
        var userprofiles= new SPAPI_UserProfile('')
        var currentUser = userprofiles.getUserProfileByName('');
        if(currentUser.status == 200)
            return currentUser;
            return null;
    function getPropertyValue(userProfileDoc,propertyName)
          var node = userProfileDoc.responseXML.documentElement.selectSingleNode('//PropertyData/Name[.="' + propertyName+ '"]');
          return node.parentNode.selectSingleNode('Values/ValueData').text;
            return '';
    function getFullName(userProfileDoc)
        var firstName = getPropertyValue(userProfileDoc,'FirstName');
        var lastName = getPropertyValue(userProfileDoc,'LastName');

         return firstName + ' ' + lastName;

    function getPhone(userProfileDoc)
        var workPhone = getPropertyValue(userProfileDoc,'WorkPhone');
        return workPhone;
    function getManager(userProfileDoc)
        var manager = getPropertyValue(userProfileDoc,'Manager');
        return manager;

      // Get User Info   
     var userProfile = getUserProfileInfo();
     var userName = getFullName(userProfile);
     var userPhone = getPhone(userProfile);
     var userManager = getManager(userProfile);

    NWF$('#' + varNameID).val(userName);
    NWF$('#' + varPhoneID).val(userPhone);
    NWF$('#' + varManagerID).val(userManager); 


Once we publish the above form, when you open an instance of that form, it’ll make a single web service call and then pull out the information we need.  I’ve put in some exception handling to cater for when properties don’t contain values.

This is what the form will look like, and you can see it auto populated the fields with the data from the User Profile of the current user:

Result Form


Form Design: Download Form Design

SPAPI Library: Download

Leave a Reply

Your email address will not be published. Required fields are marked *