Skip to main content
Nintex Community Menu Bar
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!

Best answer by TomaszPoszytek

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

View original
Translate
Did this topic help you find an answer to your question?

10 replies

TomaszPoszytek
Forum|alt.badge.img+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

Translate

Forum|alt.badge.img+5
  • 36 replies
  • October 5, 2017

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

Translate

  • Author
  • 23 replies
  • October 6, 2017

Hi Tomasz!

Thank you for your response.  

I have tried your solution but nothing happens.

Translate

  • Author
  • 23 replies
  • October 6, 2017

Hi Jaya!

Thank you for your response.

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

Translate

TomaszPoszytek
Forum|alt.badge.img+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

Translate

  • Author
  • 23 replies
  • October 8, 2017

This worked perfectly! Thank you so much, Tomasz

Translate

TomaszPoszytek
Forum|alt.badge.img+17

I'm glad to hear that Good luck in Nintexing

Regards,

Tomasz

Translate

Forum|alt.badge.img
  • 4 replies
  • May 20, 2019

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.

Translate

  • 1 reply
  • September 4, 2019

Hi Mate

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

 

Translate

Forum|alt.badge.img
  • 2 replies
  • August 21, 2020

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

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings