1
votes

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

2 Answers

1
votes

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
votes

Use the above answer, but...

Replace this with an appropriate Jquery or Javascript element name.

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