Tags

, ,


Here is a alternative solution for getting the user details using people picker dialogue window without accessing the People Picker control. I got a scenario where in I need people picker control in Sandboxed Solution. It is a limitation that we cannot use SharePoint controls in sandboxed web parts. So I tried to get the people picker dialogue window using JavaScript. Find below the procedure

My solution will pick the user names from the dialogue window and will paste it into a text box

JavaScript: (used jQuery to talk to controls)

function PeoplePicker() {
var searchString = '';
var dialogOptions = 'resizable:yes; status:no; scroll:no; help:no; center:yes; dialogWidth :575px; dialogHeight :500px;';
var dialogURL = '/_layouts/picker.aspx';
dialogURL += '?MultiSelect=False';
dialogURL += '&CustomProperty=User,SecGroup,SPGroup;;15;;;False';
dialogURL += '&EntitySeparator=;';
dialogURL += '&DialogTitle=Select People and Groups';
dialogURL += '&DialogImage=/_layouts/images/ppeople.gif';
dialogURL += '&PickerDialogType=Microsoft.SharePoint.WebControls.PeoplePickerDialog, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c';
dialogURL += '&DefaultSearch=' + escapeProperly(searchString);

commonShowModalDialog(dialogURL, dialogOptions, DelegatePeoplePickerCallback);
}

function DelegatePeoplePickerCallback(searchResult) {

var xmlDoc = $.parseXML(searchResult);
var $xml = $(xmlDoc);
var fqn = $xml.find('Entity').attr('DisplayText');

if ($("txtPeoplePicker").val() != null) {
if ($("txtPeoplePicker").val() != '') {
var contactPerson = $("txtPeoplePicker").val();
$("txtPeoplePicker").val(contactPerson + "; " + fqn);
}
else {
$("txtPeoplePicker").val(fqn);
}
$("txtPeoplePicker").focus();
}

return;
}

Declare a text box and a button for calling the PeoplePicker() function.

On click of the button “Get People” then a dialogue window will be displayed. User can search user details accross the user Profiles and get the names. After adding the user, name of the user will be pasted to the text box.

Happy Coding 🙂

Advertisements