javascriptparsingsharepointactive-directorypeoplepicker

Parsing out muiltipicker in javascript


I have created a form that pulls a person's (peoplepicker) office location automatically from AD via SharePoint's UPS and populates it in the entry field. What I'm having trouble with is pulling multiple individual's office locations and having that parse each individual's respective office location to place that in the field as well. Any ideas or help would be greatly appreciated.

Here is the form, and as you can see it can populate one person's office, but not the other individuals:


Solution

  • After further research, I want to give a thanks to the author of this useful JavaScript SharePoint library: http://spjsfiles.com/index.php?dir=SharePoint%20JavaScripts/spjs-utility/

    This library gets a user's information from a SharePoint Master list. You get this with the following function: function fillFieldDemo(){

        setFieldValue('Date', '1/1/2017');  
        setFieldValue('MM','Boston;London');    
    
        var userInfo = getUserInfo_v2(_spPageContextInfo.userId);
        setFieldValue('Person', userInfo.Name); 
    
        setTimeout(function(){
            var title = getFieldValue('Person');
            setFieldValue('Title', title);  
        }, 2000);
    }
    
    _spBodyOnLoadFunctionNames.push("fillFieldDemo");
    

    Now you can find the users' name, office, etc.

    In order to parse through multiple names in an input text box and pull their offices respectively, you can alter this function, like so:

    function fillFieldDemo() {
    
        $('.button').on('click', function() {
            var subjects = $('.ms-entity-resolved');
            var offices = [];
    
            for (var i = 0; i < subjects.length; i++) {
                var s = $(subjects[i]).prop("title");
                var print = $('.name').val(s);
    
                var userInfo = **getUserInfo_v2**(s);
    
                for (var key in userInfo) {
                    var value = userInfo.**Office**;
                }
    
                offices.push(value);
            }
    
            var input = $('.parse').val(offices);
    
        });
    }
    
    _spBodyOnLoadFunctionNames.push("fillFieldDemo");
    

    This will allow a user to input multiple names in an input text box and it will parse the names and grab the offices of each of those individuals.