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()i'Title'] != "") console.log( userProfileProperties.get_userProfileProperties()R'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!