0

Im trying to select a sharepoint peoplepicker element in my form list.

i tried:

$("#ctl00_ctl41_g_326d802c_cd66_443c_9312_18e0ff9786b9_ctl00_iwPermIterator_ctl19_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv")

But i had issues previously where the id would change, so that would not be a solution.

I also tried,

$("div[title='People Picker']")

But it would select 3 people pickers in my form list

Therefore, can someone suggest a way to select this element.

Edit: Here are 2 screenshots of the people-picker i have in my SharePoint environment.

I would like to update the reason for this behaviour is we are using a custom form (infowise forms which made all peoplepickers have the same title.)

enter image description here

enter image description here

  • which version of SharePoint are you using? – harshal gite Oct 29 '19 at 5:27
  • @harshalgite hi we are using sharepoint 2016 – Jilo Oct 29 '19 at 5:29
  • what exactly do you want to read from the people picker? – harshal gite Oct 29 '19 at 5:44
  • @harshal gite i have a drop-down, and the selected item should be appended to the peoplesPicker element. – Jilo Oct 29 '19 at 7:37
  • Normally i would something such as $("div[title='People Picker']").append(SelectedDropDownItem) – Jilo Oct 29 '19 at 7:42
0

As discussed earlier, please modify the code snippet with index to choose the people picker needed:

$("div[title='People Picker']")[0]
  • Hi, we are using Sharepoint 2016, for my case all 3 people picker's title is People Picker for some reason.. – Jilo Oct 29 '19 at 5:31
  • Above is testing in SharePoint 2013 in my side, I will test in SharePoint 2016 again and give you update later. – Jerry_MSFT Oct 29 '19 at 5:33
  • I tested in SharePoint 2016, just the same as 2013, the each people picker title will be the samne as each field name in the list form, Can you please try to create a new list for a test ? – Jerry_MSFT Oct 29 '19 at 5:41
  • I will update the capture with SharePoint 2016 environment. – Jerry_MSFT Oct 29 '19 at 5:42
  • 1
    thanks, we are using Sharepoint 2016 on premise if that helps, i'll get back to you when i reach my office. – Jilo Oct 29 '19 at 5:42
0

You can do this using the functions provided by SharePoint itself. The following line gives you the id of the top level element of your people picker (replace "YourFieldInternalName" by internal name which you have given).

var pickerDivID = WPQ2FormCtx.ListSchema.YourFieldInternalName.TopLevelElementId

If this does not work, WPQ2FormCtx might not be the correct object. Just open browser console and type WPQ or FormCtx, you will get some like WPQ2FormCtx or WPQ4FormCtx. Use that in the above statement.

You can use this ID wherever you want. To get values from peoplepicker as shown below.

var pickerObject = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDivID];

This object contains all the information in the people picker column of the form.

Open the form in new page or by going to top ribbon -> list -> default new form. Try getting that wpformctx here. And use that one in the code.

Ideally it should work with infowise customization as well because SharePoint fields remain the same.

  • hi @harshal gite i tried all 3 (WPQ2FormCtx, FormCtx, WPQ ) in google chrome console, they all return VM5612:1 Uncaught ReferenceError: WPQ is not defined Do i need some sort of library to use them? – Jilo Oct 29 '19 at 6:50
  • type WPQ or formctx and do not hit enter. you will be get the correct one in intellisense. No you do not need any library – harshal gite Oct 29 '19 at 6:52
  • i typed in WPQ, only varPartWPQ2 exists as an object, The rest are are not defined. i also typed formctx but did not get anything recommended by the intellisense. – Jilo Oct 29 '19 at 7:25
  • Are you trying with your form open in modal dialogue? – harshal gite Oct 29 '19 at 7:27
  • @ harshal gite, Actually we are using infowise forms. And we are opening the forms as Tabs with the help of infowise. – Jilo Oct 29 '19 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.