Skip to main content
Nintex Community Menu Bar

Retrieve User Profile Details on Nintex Form for Office 365

  • May 20, 2017
  • 3 replies
  • 85 views
  • Translate

Forum|alt.badge.img+6

Retrieve User Profile Details on Nintex Form for Office 365

Unlike the Nintex on-premise version , the User Profile Lookup function isn’t available yet in the Office 365 Nintex forms [Hopefully Nintex will add it in the future versions]. So here is a solution on how you can fetch the user profile properties using a custom JavaScript code.

 

Please refer my blog-post Retrieve User Profile Details on Nintex Form for Office 365 [Step – By – Step] 

to view the step-by-step process.

 

 

Common Code (Add this code inside the Site Assets folder and name it “sp.userprofile.js“)

—————————————————————————————————————————————–

function SPUserProfile(strAccountName, OnComplete, OnError) {
var currentObject = this;
var userprofile = null;

this.getProperty = function (propertyName) {
if (this.userprofile == null) {
propertyValue = “Userprofile not initialized or error fetching user profile”;
} else {
var propertyValue = NWF$.grep(this.userprofile.d.UserProfileProperties.results, function (k) {
return k.Key == propertyName;
});
if ((propertyValue == null) || (propertyValue.length == 0)) {
propertyValue = null;
}
}
return propertyValue;
}

this.getDisplayName = function () {
return this.userprofile.d.DisplayName;
}

this.getDepartment = function () {
var propVal = this.getProperty(“Department”);
if (propVal == null) {
return ”;
} else {
return propVal[0].Value;
}
}

this.getMobilePhone = function () {
var propVal = this.getProperty(“MobilePhone”);
if (propVal == null) {
return ”;
} else {
return propVal[0].Value;
}
}

this.getTitle = function () {
return this.userprofile.d.Title;
}

this.getEmail = function () {
return this.userprofile.d.Email;
}

function execCrossDomainRequest() {

if ((SP == null) || (SP.RequestExecutor == null)) {
setTimeout(execCrossDomainRequest, 500);
} else {
var url = appweburl + “/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(@v)?@v='” + encodeURIComponent(strAccountName) + “‘”;
var requestHeaders = {
“Accept”: “application/json;odata=verbose”
};
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: url,
contentType: “application/json;odata=verbose”,
method: “GET”,
headers: requestHeaders,
success: function (data) {
currentObject.userprofile = JSON.parse(data.body);
OnComplete(currentObject);
},
fail: function (error) {
userprofile = null;
OnError(error);
},
});
}
}
var appweburl = decodeURIComponent(getQueryStringParameter(“SPAppWebUrl”));
NWF.FormFiller.Events.RegisterAfterReady(function () {
execCrossDomainRequest();
});
}

—————————————————————————————————————————————–

  • Inside the custom JavaScript paste the below code

—————————————————————————————————————————————–

var hosturl = decodeURIComponent(getQueryStringParameter(“SPHostUrl”));
NWF$.getScript(hosturl + “/SiteAssets/sp.userprofile.js”).then(function () {
NWF$(document).ready(function () {
NWF$(‘#’ + EmployeeName).change(function () {
OnEmployeeChange();
});
OnEmployeeChange();
});
});

function OnEmployeeChange() {
var selectedEmployee = NWF$(‘#’ + EmployeeName).val();
selectedEmployee = selectedEmployee.split(‘;’);
if (selectedEmployee[0] == “”) {
NWF$(“#” + JobTitle).val(”);
NWF$(“#” + Department).val(”);
return;
}
var userProfile = new SPUserProfile(selectedEmployee[0],
function (data) {
NWF$(“#” + JobTitle).val(data.getTitle());
NWF$(“#” + Department).val(data.getDepartment());
},

function (error) {
NWF$(“#” + JobTitle).val(”);
NWF$(“#” + Department).val(”);
alert(‘An error occurred while fetching userprofile data’);
});
}

—————————————————————————————————————————————–

Thanks !!

Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+4

Hi Saud,

    Thank you very much for this useful post. I have a similar requirement and will definitely use your approach.

 I have a question here... Can I just use <AppPermissionRequests><AppPermissionRequest Scope=”http://sharepoint/social/tenant&#8221; Right=”Read” />  while getting Permission for XML for Nintex Form.

My client might only interested in READING the property. Can I avoid "write" part ?

Thanks,

Rahul

Translate

Forum|alt.badge.img+6
  • Author
  • 40 replies
  • August 14, 2017

Sure, if reading the user profile is the only requirement , then you can avoid the "Write" permission.

Translate

nintexbadger

User Profile Lookup Runtime action is now available in Office 365, but I found I still needed to follow your directions to grant Nintex Form App permissions which does not seem to be clearly documented anywhere other than your blog post so thank you for your write-up:

Retrieve User Profile Details on Nintex Form for Office 365 [Step – By – Step] 

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings