Solved

How to auto populate a people picker field based on another people picker field?


I have two people picker fields and what I want to do is to auto populate the second field with the same data I entered in the first field (not current user). 

Is there a rule or javascript code to make this possible? I am new to Nintex Forms and I have no idea on how to this one. Your help will be greatly appreciated. Thanks!

icon

Best answer by TomaszPoszytek 6 October 2017, 15:51

View original

10 replies

Userlevel 7
Badge +17

Hi!

If you are using Nintex Responsive Forms, then unfortunately this is not yet possible - you cannot set a rule on the people picker field for "Set Value". Sorry.

If, however, you are working with Standard Forms, then the easiest way is to use the NF.PeoplePickerApi (People Picker Extensions - Nintex Forms) and then to write a javascript, that sets the other field value once the value in the first place changes, ex.:

NWF$(document).ready(function () {
    var firstPPPickerFieldl = NWF$('#' + var_People1);
    var secondPPPickerField = new NF.PeoplePickerApi('#' + var_People2);
    NWF$(firstPPPickerField).change(function () {
        secondPPPickerField.search(NWF$(firstPPPickerField).val()).done(function (data) {
            secondPPPickerField.add(data[0]);
        });
    });
});‍‍‍‍‍‍‍‍‍

The var_People1 and var_People2 are the JavaScript variables of the PP 1st and 2nd control.

I haven't tested this particular script, but imo it should work, or at least point to the correct solution

Regards,

Tomasz

Badge +5

Hi TC N ,

This is something working code for your requirement in on Prem, not sure if people picker extensions available in O365 or not.

NWF.FormFiller.Events.RegisterAfterReady(function () {
         var _personName = new NF.PeoplePickerApi("#" + varRequestorName);
        

   _personName.added(function () {
                        var _txtUserID = NWF$("#" + varRequestorName).val();
                        _txtUserID = _txtUserID.replace(/;/, ""); //THIS IS IMPORTANT
                          var _SecondpersonName = new NF.PeoplePickerApi("#" + varCreatedFor);
                        _SecondpersonName.search(_txtUserID).done(function (data) {
                                       _SecondpersonName.add(data[0]);
                           });

                     }); // End of added function
_personName.removed(function () {
                  var _SecondpersonName = new NF.PeoplePickerApi("#" + varCreatedFor);
                  _SecondpersonName.clear();
}); // end of removed function
});

as there is no change function available for people picker control you have to make use of added & removed methods as per the documentation mentioned in Tomasz Poszytek Champion's reply

Hi Tomasz!

Thank you for your response.  

I have tried your solution but nothing happens.

Hi Jaya!

Thank you for your response.

I am in O365, I tried your solution but sadly, nothing happens.

Userlevel 7
Badge +17

Honestly speaking it seems that the NF.PeoplePickerAPI is not present in the Office 365. I checked that object and there is no such node.

Anyway, I have other solution for you. Tested and working. Use the following code:

NWF.FormFiller.Events.RegisterAfterReady(function () { 
     NWF$(document).ready(function() {
          NWF$("#"+var_People1).change(function() {
               // first wipe out existing state of the field
               NWF$("#"+var_People2).val("");
               NWF$("#"+var_People2).closest("div.ip-container").find("div.ip-item").each(function() { NWF$(this).remove(); });
               // then fill it with the scope set in field 1
               NWF$("#"+var_People2).val(NWF$(this).val());
               NWF$(this).closest("div.ip-container").find("div.ip-item").each(function() { NWF$("#"+var_People2).closest("div").find("textarea").before(NWF$(this).clone(true,true)); });
          });
    });
});

Obviously the var_People1 and var_People2 are JavaScript variables set for you two fields:

Bon appetit!

Regards,

Tomasz

This worked perfectly! Thank you so much, Tomasz

Userlevel 7
Badge +17

I'm glad to hear that Good luck in Nintexing

Regards,

Tomasz

Badge

Hi Tomasz,

Thanks for your suggestion!

 

In my case I want to prepopulate People control of Nintex form (o365) classic form based on users email address.

I have user id and user email address in my javascript.

now using these 2 values I want to populate the people control in nintex form.

Hi Mate


Can we populate manager of first people picker to the second one ?


 

Badge

This is not working on my form. Could you please help me out?

Reply