Skip to main content
Nintex Community Menu Bar

Loop through People Picker Extension

  • February 7, 2018
  • 3 replies
  • 23 views

Forum|alt.badge.img+2

I'm trying to figure out, how it's possible to use the PeoplePicker API multiple times. (Add a SP-User from a textfield into the people picker control in a repeating section.)

Following is a sample of my actual code:

function test(){
NWF.FormFiller.Events.RegisterAfterReady(function () {
var $row = NWF$(this);
var rownumb = NWF$('.rows input').val();
var collection = {};

NWF$(".your-repeater .nf-repeater-row:not('.nf-repeater-row-hidden')").each(function (){
var $migrationfield = $row.find(".migrationfield input").val();
for(var i=0;i<rownumb;i++){
collection = new NF.PeoplePickerApi('#' +peoplepicker);
collection.search($migrationfield).done(function (data) {
collection.add(data[0]);
});
}
});
});
}

The problem it returns in the dev-mode is following: 

Uncaught TypeError: cannot read property 'add' of undefined.

So I clearly see that the add method does not work, but why not? Any Suggestions?

3 replies

Forum|alt.badge.img+14
  • Scholar
  • February 7, 2018

can you describe your design bit clearer (post a screenshot)?

are both source text box and people controls in repeating section? or just people control?

both on the same row? the same repeating section?

how/where do you call test() function from?


Forum|alt.badge.img+2
  • Author
  • February 8, 2018

Both (the textbox and people control) are in the repeating section. So therefore in the same row as well.
The Test Function gets called by a Button. But later on the function gets called on change. Do you have any idea on how to loop it? 


Forum|alt.badge.img+14
  • Scholar
  • February 9, 2018

you do not need any looping at all.

try following

NWF.FormFiller.Events.RegisterAfterReady(function (){
   NWF$('.TxtBoxClass input.nf-associated-control').change(function(){
           var pp = new NF.PeoplePickerApi(NWF$(this).closest('.nf-repeater-row').find('.PPClass input.nf-peoplepicker')[0]);
           pp.clear();
           pp.search(this.value).done(function(data){
              pp.add(data[0]);
           })
   })
})

‌    ‌