Cannot find a successful way to access user profile details in forms


Badge +2

I've been trying all the ways I can find to access the currently logged in users profile details from Nintex forms for Office 365. It is driving me mad.

 

Nothing I've tried works.

The closest I've got is to be able to load SPServices - I can return the version number just fine. But when I try to access any data, I always get a blank response.

For example, with this in the form's custom JS:

NWF$(function(){      console.log('##### ======= START HERE ======= #####');       console.log(NWF$().SPServices.Version());       var userAccount = NWF$().SPServices.SPGetCurrentUser({           fieldName: "Title",            debug: false      });      var userName = NWF$().SPServices.SPGetCurrentUser({           fieldName: "UserName"      });      var thisSite = NWF$().SPServices.SPGetCurrentSite();       console.log('USER ACCOUNT: ',userAccount);      console.log('USER NAME: ',userName);      console.log('SITE NAME: ',thisSite);      alert('SITE NAME: '&thisSite);            NWF$().SPServices({           operation: "GetUserInfo",           async: false,           userLoginName: NWF$().SPServices.SPGetCurrentUser(),           completefunc: function (xData, Status) {                NWF$(xData.responseXML).find("User").each(function() {                     alert(NWF$(this).attr("Name"));                });           }      });            console.log('##### ======= FINISH HERE ======= #####'); });

Each of the variables comes back blank and the final part is never shown so it presumably fails.

 

I've also tried directly accessing the data using JSOM by adding the following to the custom JavaScript includes:

https://nhsengland.sharepoint.com/_layouts/15/init.js

https://nhsengland.sharepoint.com/_layouts/15/sp.runtime.js

https://nhsengland.sharepoint.com/_layouts/15/SP.js

https://nhsengland.sharepoint.com/_layouts/15/SP.UserProfiles.js

And the following custom JavaScript:

NWF$(function(){      console.log('##### ======= START HERE ======= #####');       // ensure that the SP.UserProfiles.js file is loaded before the custom code runs.      SP.SOD.executeOrDelayUntilScriptLoaded(getUserProperties, 'SP.UserProfiles.js');     var userProfileProperties;       function getUserProperties() {         var clientContext = new SP.ClientContext.get_current();         var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);         userProfileProperties = peopleManager.getMyProperties();           console.log(userProfileProperties);         clientContext.load(userProfileProperties);         clientContext.executeQueryAsync(onRequestSuccess, onRequestFail);     }       // This function runs if the executeQueryAsync call succeeds.     function onRequestSuccess() {         if (userProfileProperties.get_userProfileProperties()['Title'] != "")             console.log( userProfileProperties.get_userProfileProperties()['Title'] );     }       // This function runs if the executeQueryAsync call fails.     function onRequestFail(sender, args) {         console.log('REQUEST FAILED');     }            console.log('##### ======= FINISH HERE ======= #####'); });

But that always fails.

 

Surely there must be some way of accessing the user profile details?!?! Please help!


14 replies

Badge +9

Hi Julian,

Maybe this post can help.

This is not exactly what you need but it gives a direction.

Regards,

Christophe

Badge +2

Thanks Christophe! I have made a little progress. Following that post, I managed to get the permission value back. However, I still can't get the user profile data. So I'm wondering if I'm missing something on the JSON side now. Good grief, surely other people do this stuff? How can it be so difficult!

Badge +2

Having done further research, here are my current findings and it isn't pretty.

As far as I can tell, it isn't currently possible to call anything from /_layouts/15/SP.UserProfiles.js as it is never activated though I can see it being loaded by FormsPart.aspx. No matter how you then try to call it from your custom JS, it will never work. If you wrap the call in "SP.SOD.executeOrDelayUntilScriptLoaded(loadProfileData, 'SP.UserProfiles.js');" the script is never executed. If you try to call it without that, it always fails.

You CAN call get_current()/get_web()/get_currentUser() but that only gives you access to limited information and not the full profile.

I can only think that this relates to the structure of Nintex Forms and the complex way things are loaded. e.g. the SP files are loaded by FormsPart.aspx but the form code is run from NFLaunch.aspx. I'm also guessing that this is the reason that the user profile function available to on-prem users is not made available to Office 365 users.

Unless someone can find an alternative method, I'm afraid this makes Nintex Forms extremely limited except purely for use in Workflows - Even InfoPath can be made to lookup user profile information! Looks like we will be looking elsewhere for a tool that will support us.

Very disappointing.

Badge +9

Julian,

Which user's info are you searching for?

Christophe

Badge +2

Initially:

  • Department
  • Team
  • Work Email (these users are not using Exchange Online)
  • Phone Number
  • The users manager - for which I will then need to lookup the managers contact details.

These need to be from the SharePoint Online User Profile service not from AAD.

Badge +9

Julian,

Maybe you can use the Workflow Query User Profile action

Regards,

Christophe

Badge +2

Thanks for the suggestion Christophe. I didn't really want to have to use a workflow to populate that data but rather to have it populate when someone opens the new form. I'm sure I can update the data using a workflow & I may have to resort to that but it means that the person filling in a new form cannot see whether the data is correct as they are filling it in. Not really a very good UX.

This should be easy and MS provide the helper libraries to make it happen in the front-end. It would be easily fixed if Nintex made the libraries available to the forms app.

Badge +8

Julian Knight​ It looks like our community has several unanswered questions surrounding this topic for those of us using O365.

I've pulled this data before using REST in a SharePoint add-in with custom jQuery, but never within the context of a Nintex Form. I'll see if I can dabble with this and find a workaround until the on-prem user profiles are supported here as well.

Badge +8

Very nice Frank Field! I'll have to check out these new features – thanks for sharing!

Userlevel 5
Badge +9

Hi Julian,

Actually, it's normal that you cannot get user profile information from Nintex Forms in O365.

It's related to app permissions.

Your Nintex Forms app doesn't have permission to read information in user profile.

It's the same for Nintex Workflow. Here's the documentation regarding how to give those permissions to your Nintex Workflow app :

http://help.nintex.com/en-US/O365/Default.htm#cshid=1240

I've tried to give Nintex Forms app read permission to the user profile using this technique :

Retrieving User Profile Properties in a SharePoint 2013 Workflow - SharePoint Community

and then retry to execute Javascript to get user profile info, but I didn't managed to do that... sorry.

I've seen another post dealing with the same problem : REST access denied from nintex forms office 365.

Badge +2

Thanks for the update Frank. Is that just for mobile though? Certainly no update is showing for our Office 365 installation of Forms and no profile lookup function appears to be available.

Badge +2

Thanks Caroline.

In fact, it appears that the app specifically does not allow access to the profile:

  • Let it create or delete document libraries and lists in this site collection.
  • Let it create or delete document libraries and lists in this site.
  • Let it share its permissions with other users.
  • Let it access basic information about the users of this site.

Odd though that there is no error generated. I would have expected an error to be generated when accessing a disallowed reference.

I can't find any way to change the permissions for Forms.

I will have to try the REST method to see if that works but I've already wasted a lot of time on this that I don't really have.

Thanks everyone for your input so far, lets hope we can get a formal solution soon.

Userlevel 5
Badge +9

As the app doesn't have permission to access user profile, any javascript that will query the user profile will return access denied error.

If I were you, I won't try any javascript until the Nintex Forms app has permission to access user profile to avoid wasting time.

To change Nintex Forms app permission, you need to be administrator of your tenant (as giving user profile read permission requires tenant administrator permission). Here's a link where it explains how to it (to get the "App Id", you can go to "Site settings" then "Site app permissions" and next to "Nintex Forms for Office 365" the app id is between "i:0i.t|ms.sp.ext|" and "@") :

Site App Permissions

In our case, we need the following App's Permission Request XML :

<AppPermissionRequests><AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="Read"/></AppPermissionRequests>

You can also vote for this idea to have the userprofilelookup function in Forms in O365:

userprofilelookup Runtime Function – Customer Feedback for Nintex

Userlevel 4
Badge +12

You're now able to use userprofilelookup in Office 365 too. You need to add a permission to the nintex app though, as described here:

https://help.nintex.com/en-US/o365/#o365/O365WorkFlow/Admin/UserProfilesSvc.htm?Highlight=user%20profile 

 

Maybe you give it a try.

Best regards

Enrico

Reply