SharePoint userProfileProperties JSOM (JavaScript Object Model) -
i tryin info peoplemanager.getmyproperties() function. object,some values null.when check user profile management,i can see value. how can fix 1 ?
there working code object.
note : want access custom property user profile created before. can see property in object value not coming.
thank all..
$(document).ready(function(){ sp.sod.executeordelayuntilscriptloaded(loaduserdata, 'sp.userprofiles.js'); }); var userprofileproperties; function loaduserdata(){ //get current context var clientcontext = new sp.clientcontext.get_current(); //get instance of people manager class var peoplemanager = new sp.userprofiles.peoplemanager(clientcontext); //get properties of current user userprofileproperties = peoplemanager.getmyproperties(); clientcontext.load(userprofileproperties); //execute query. clientcontext.executequeryasync(onsuccess, onfail); } function onsuccess() { console.log(userprofileproperties) } function onfail(sender, args) { console.log("error: " + args.get_message()); }
try below code , let me know. works fine me. have passed user name instead of account. can pass user account here.
function getuserproperties(username) { var clientcontext = new sp.clientcontext.get_current(); var peoplemanager = new sp.userprofiles.peoplemanager(clientcontext); var profilepropertynames = ["firstname", "lastname", "customproperty"]; //have load needed properties here var targetuser = username.trim(); var userprofilepropertiesforuser = new sp.userprofiles.userprofilepropertiesforuser(clientcontext, targetuser, profilepropertynames); userprofileproperties = peoplemanager.getuserprofilepropertiesfor(userprofilepropertiesforuser); clientcontext.load(userprofilepropertiesforuser); clientcontext.executequeryasync(onsuccess, onfail); } function onsuccess() { // userprofileproperties result index same properties loaded above var firstname=userprofileproperties[0]; var lastname=userprofileproperties[1]; var customprop=userprofileproperties[2]; }
mark answer if helps.
Comments
Post a Comment