Skip to the content Skip to the Navigation

Workflow Excellence

  • Workflow Excellence
  • Blog
  • Contact
Blog
  1. HOME
  2. Blog
  3. Nintex Forms
  4. Nintex Forms – Querying User Profiles
December 30, 2020 / Last updated : December 30, 2020 Vadim Tabakman Nintex Forms

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;
        } 
        else
        {
            return null;
        }    
    }
    
    function getPropertyValue(userProfileDoc,propertyName)
    {
        try
        {
          var node = userProfileDoc.responseXML.documentElement.selectSingleNode('//PropertyData/Name[.="' + propertyName+ '"]');
          return node.parentNode.selectSingleNode('Values/ValueData').text;
         }
         catch(e)
         {
            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); 
    
});

Result

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

Downloads

Form Design: Download Form Design

SPAPI Library: Download

Categories
Nintex Forms
Tags
JavascriptNintexNintex FormsSPAPIUser Profile

Leave a Reply Cancel reply

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

Nintex Forms

Previous article

Nintex Forms – Date Calculations with Javascript
December 30, 2020
Nintex Workflow

Next article

Nintex Workflow – What is a User Defined Action?
December 30, 2020

Recent posts

Nintex Workflow Cloud and XML Complex Nodes

December 10, 2021

Nintex Workflow Cloud and XML as Temp Storage

December 9, 2021

Nintex Workflow Cloud – PadRight

April 13, 2021

Automating a Shadowing Program

January 14, 2021

Nintex acquires K2

December 31, 2020

Nintex Workflow Cloud – Archiving Documents

December 31, 2020

Goodbye SharePoint 2010 Workflows Online

December 31, 2020

Nintex Workflow Cloud – Math Power Component Workflow

December 31, 2020

Nintex Workflow Cloud – Looping

December 31, 2020

Nintex RPA – Processing Filtered Excel Data

December 31, 2020

Category

  • Drawloop
  • Nintex Forms
  • Nintex Reporting
  • Nintex RPA
  • Nintex Workflow
  • Nintex Workflow Cloud
  • Nintex Workflow for Office 265
  • PowerShell
  • Promapp
  • Tools
  • Training

Archive

  • December 2021
  • April 2021
  • January 2021
  • December 2020

Interesting Sites

Nintex
Simplifying Processes
Jesse McHargue
Around SharePoint
Haley Walsh
Kok Koon
Nicole Vesser

Copyright © Workflow Excellence All Rights Reserved.

Powered by WordPress & Lightning Theme by Vektor,Inc. technology.

MENU
  • Workflow Excellence
  • Blog
  • Contact