AnsweredAssumed Answered

Filtering People picker based on other people picker in Nintex Form 2013

Question asked by weezer22 on Nov 1, 2016

I build Nintex Form 2013 to populate username and manager in people picker. I used the following steps.

https://wowsomuch.com/sharepoint/nintex-forms-automatically-filling-people-picker-control/

The post above it will work if we populate user when the Nintex form the load however once the form load and you try to change username, the manager fill will not update based on the username. Is there anyway i could filter manager people picker based on username people picker which support if username changed after the form load?. Thank you

    /*global NWF$ */
   
    NWF$(document).ready(function () {
        NWF.FormFiller.Events.RegisterAfterReady(function () {
            try {
                getManager();
                var ins = new NF.PeoplePickerApi('.antragsteller input');
                ins.added(getManager);
                ins.removed(clearManager);
            } catch (err) {
               
                return;
            }
        });
    });
   
    function clearManager() {
        var managerPicker = new NF.PeoplePickerApi('.manager-control input');
        managerPicker.clear();
    }
   
    function getManager() {
        // Initialise Manager People picker control
        var managerPicker = new NF.PeoplePickerApi('.manager-control input');
       
        if (NWF$.trim(NWF$('.manager-control input').val()) !== '') {
            return;
        }
       
        if (NWF$.trim(NWF$('.antragsteller input').val()) === '') {
            return;
        }
        // Query the User Profile Service for the current user's manager
        var ManagerAccount;
        // var xxx = NWF$().SPServices.SPGetCurrentUser();
        var name = NWF$('.antragsteller input').val().replace(/;/, "");
        //var user = JSON.parse(name);
        //var userid = user[0].value;    // User ID
        var userid = name;
   
   
        NWF$().SPServices({
            operation: "GetUserProfileByName",
            async: false,
            //AccountName: NWF$().SPServices.SPGetCurrentUser(),
            AccountName: userid,
            completefunc: function (xData, Status) {
                ManagerAccount = getUPValue(xData.responseXML, "Manager");
            }
        });
   
        //managerPicker.ready(function () {
        // clear control
        managerPicker.clear();
        //search for Manager Name and add first search result
        managerPicker.search(ManagerAccount).done(function (data) {
            managerPicker.add(data[0]);
            //  managerPicker.add({ value: "Jürgen Weber", type: "user", email:"juergen.weber@kob.de", label:"Jürgen Weber"});
            // });
   
        });
    }
   
   
    // ****************************************************
    // Function to retrieve User Properties
    // ****************************************************
   
    function getUPValue(x, p) {
        var thisValue = NWF$(x).SPFilterNode("PropertyData").filter(function () {
            return NWF$(this).find("Name").text() == p;
        }).find("Values").text();
        return thisValue;
    }

Outcomes