Skip to content

Instantly share code, notes, and snippets.

@Sinetheta
Created April 5, 2012 03:02
Show Gist options
  • Save Sinetheta/2307660 to your computer and use it in GitHub Desktop.
Save Sinetheta/2307660 to your computer and use it in GitHub Desktop.
JS: SharePoint target user by idir
var GetUserProfileByName = function (accountName) {
var soap = '';
accountName = accountName || ''; //Blank accountName returns results for current user
soap += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
soap += ' <soap12:Body>';
soap += ' <GetUserProfileByName xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">';
soap += ' <accountName>' + accountName + '</accountName>';
soap += ' </GetUserProfileByName>';
soap += ' </soap12:Body>';
soap += '</soap12:Envelope>';
return $.ajax({
type: "POST",
contentType: "text/xml;charset='utf-8'",
url: '/_vti_bin/UserProfileService.asmx',
data: soap,
dataType: "xml"
});
}
$.when(GetUserProfileByName()).done(function (data, textStatus, jqXHR) {
$(data).find("PropertyData").each(function (idx, val) {
var name = $(val).find('Name').text();
if (name === "AccountName") {
currentUser = $(val).find('Value').text();
}
});
if (currentUser === 'IDIR\\TARGET') {
//user specific code
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment