Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Returned Value in Function showing undefined - REST, SharePoint javascript

$
0
0

i'm trying to get the picture details from his user profile in the pictureRetrieve function. when i check the console the PictureDetails value exists for each item . But what i'm trying to achieve is to return the value to the completedetails function.

But the line that calls the pictureRetrieve function runs i get undefined as a result. Not sure if this is a scope problem or return keywords run differently in json.

any help would be much appreciated

function CompleteDetails() { var requestUri = _spPageContextInfo.webAbsoluteUrl +"/_api/Web/Lists/getByTitle('OrganisationalChart')/items?$select=Id,user/Title,user/Id,user/Name,Boss/Id,Boss/Title,PictureUrl,Designation&$expand=user,Boss"; $.ajax({ url: requestUri, type: "GET", async:false, headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { var dataResults = data.d.results; console.log(dataResults); for (var i = 0; i < dataResults.length; i++) { var userDetails = dataResults[i]['user'].Name.split('|')[1]; var employeeId = dataResults[i]['user'].Id.toString(); var employeeName = dataResults[i]['user'].Title var Designation = dataResults[i].Designation != null ? dataResults[i].Designation : ''; var reportingManager = dataResults[i]['Boss']['Id'] != null ? dataResults[i]['Boss']['Id'] : ''; reportingManager = reportingManager.toString(); //Get the user profile picture for each user userPicture = pictureRetrieve(userDetails); } }, failure: function (r) { alert(r.d); }, error: function (r) { alert(r.d); } }); } var pictureRetrieve = function GetPictureUrl(user) { var requestUri = _spPageContextInfo.webAbsoluteUrl +"/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+user+"'"; $.ajax({ url: requestUri, type: "GET", async:false, headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { var DataRes = data.d.PictureUrl; var PictureDetails = data.d.PictureUrl != null ? data.d.PictureUrl : 'nouserimageurl'; console.log(PictureDetails);

return PictureDetails;

}, failure: function (r) { alert(r.d); }, error: function (r) { alert(r.d); } }); }





Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>