Saturday 5 October 2013

Get User Profile Picture URL Using JQuery

I encountered an issue while working on a discussion board in SharePoint 2007. The issue is the user's profile picture is not displaying in the flat view of the discussion board even though there is a picture associated with the user profile. Instead the picture from this url "_layouts/images/person.gif" is displaying. So in order to fix this issue, I just used jQuery.

Here is the sample script on how to get the user profile picture url through jQuery:

function spjs_QueryPicURL(itm){
var pic=null;

var query = "<Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>"+itm+"</Value></Eq></Where></Query>";
$().SPServices({
    operation: "GetListItems",  
    async: false,
    listName: "6ccdab10-1068-4d14-8f72-2a55f02938da",
CAMLQuery: query,
    CAMLViewFields: "<ViewFields><FieldRef Name='Picture' /></ViewFields>",  
    completefunc: function (xData, Status) {    
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
        pic = $(this).attr("ows_Picture");
      });
    }
  });
 
if(pic == 'undefined')
pic=null;

return pic;
}


**** Note:

listName is the list ID of User Information List

****************


No comments:

Post a Comment