cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

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

Jump to solution

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!

Labels: (1)
Tags (1)
Reply
7 Replies
Workflow Hero

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

Jump to solution

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

Regards, Tomasz Poszytek
Reply
Workflow Hero

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

Jump to solution

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

0 Kudos
Reply
Workflow Hero

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

Jump to solution

Hi Tomasz!

Thank you for your response.  

I have tried your solution but nothing happens.

0 Kudos
Reply
Workflow Hero

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

Jump to solution

Hi Jaya!

Thank you for your response.

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

0 Kudos
Reply
Workflow Hero

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

Jump to solution

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

Regards, Tomasz Poszytek
Reply
Workflow Hero

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

Jump to solution

This worked perfectly! Thank you so much, Tomasz

Reply
Workflow Hero

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

Jump to solution

I'm glad to hear that Good luck in Nintexing

Regards,

Tomasz

Regards, Tomasz Poszytek
Reply