Get resolved SPUser IDs from Sharepoint 2010 PeoplePicker

1.6k views Asked by At

I try to get selected user IDs from people picker control as below:

function GetUserIdsFromPP() {
    var xml = _picker.find('div#divEntityData');
    var visiblefor = new Array();

    xml.each(function (i, row) {
        var data = $(this).children().first('div').attr('data');
        var xmlDoc;

        if (window.DOMParser) {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(data, "text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = false;
            xmlDoc.loadXML(data);
        }
        var uid = xmlDoc.getElementsByTagName('Value')[0].firstChild.nodeValue;
        visiblefor.push(uid);
    });

    return visiblefor;
}

The problem is that sometimes XML doesn't contain <Key>SPUserID</Key><Value>1</Value> and I get FQUN (user login with domain name).

What is the better way to resolve selected SPUserIds from PeoplePicker control?

2

There are 2 answers

0
marcinn On

This is how resolve emails from people picker control on client side

function GetEmailsFromPicker() {
    var xml = _picker.find('div#divEntityData');
    var result = new Array();

    xml.each(function (i, row) {
        var data = $(this).children().first('div').attr('data');
        var xmlDoc;

        if (window.DOMParser) {
            parser = new DOMParser();
            xmlDoc = parser.parseFromString(data, "text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = false;
            xmlDoc.loadXML(data);
        }

        var emailIndex = -1;

        for (var i = 0; i < xmlDoc.childNodes[0].childNodes.length; i++) {
            var element = xmlDoc.childNodes[0].childNodes[i];
            var key = element.childNodes[0].childNodes[0].nodeValue;
            if (key == 'Email') {
                var uid = xmlDoc.childNodes[0].childNodes[i].childNodes[1].childNodes[0].nodeValue;
                result.push({ EMail: uid });
                break;
            }
        }
    });

    return result;
}
0
Jack On

Use the above answer, but...

Replace this with an appropriate Jquery or Javascript element name.

var xml = _picker.find('div#divEntityData');