Thursday, September 18, 2008

Integrating a people picker in your InfoPath Forms



We've all wanted to do it at one point or another. Either when creating our own workflow forms or when using Infopath to store business data in a SharePoint Form Library: A way to choose a manager, assistant or co worker using the people picker control.


It is really not that hard, once you realise that it is not called people picker but Contact Selector in Infopath. Available as an extra Active X control to place on your form.


Here a great short artcle by a fellow blogger on how to use the control.








In his blog he shows a screenshot of the finshed xlm schema where the fields themselves are repeating fields. no need for that though. simple non repeating fields within a repeating group is good enough.




Also you might want to have more than one selector on your page. Nothing simpler than that. Simply create a new base group (for example manager) and then right click the existing Person repeating group and choose Reference








Then choose the newly created group for the copy of the Person element

9 comments:

amo368 said...

Not sure if you will read this but I got this thing to work and it seems as if it's causing infopath to crash when I print the form that was submitted... I can print it from design mode and if I dont have the "people picker" box filled in yet... any suggestions?

Unknown said...

Hmm. That's an interesting one. Never tried printing the form as I only use it for online workflows.
How about creating a separate Print View for the form and tying the underlying AccountID field in as a textbox on that form.
Print views are pretty simple:
a) create a new View
b) copy all the controls you want to include and modify to hearts content to look good on paper
c) go to the original View's Properties and specify the new View to be the Print View for it.

Regards,

Alex

DAP said...

Works for a second picker (thanks!); however, even if I make the fields non-repeating, I can still select multiple people. Ideas? I tried using validation to look out for ";" between two entries, but "contains" does not catch this.

I'd also like to limit people selections to only those with e-mail addresses - my company has several listings for some people (some with, some without).

Unknown said...

As the people picker uses the SharePoint system as a source for the list of people I would try limited the scope of the picker using the stsadm command.

stsadm -o setproperty -pn Peoplepicker -searchadcustomquery [query goes here] -url http://yoursite

And then add the custom AD query you want to limit to. That setting would take effect for the whole sitecollection where you apply that command.

Not sure how you would limit the picker to one person though. Some clever xsd validation might do the trick.

DAP said...

I'm not a programmer. I try to stick to the WYSIWYG interface. I do understand programming - sort of. Where would I put the stsadm command to call the custom query?

DAP said...

I am able to use validation to keep the user from selecting multiple contacts. I'm checking into the AD filter, but will need assistance to implement.

For now anyway, I can also keep the user from selecting a non-standard contact, but only after some of the coding that produces the contact's e-mail address fails (and produces the "some rules were not applied" error). Then my informative message appears telling the user to try again.

Unknown said...

The stsadm command comes with SharePoint and needs to be executed with administrative priviledges on the SharePoint server itself. Ask your SharePoint Administrator for some advice on that command, as it is the most importand command line SharePoint administrators will ever need.

You do not need any programming skills to be able to configure SharePoint, but sound technical understanding of the platform as a whole is always an advantage :-)

Jovix said...

This is a great post, I'm really getting some good use out of this. I did run into an issue though, after adding 3 or more contact selectors, I'm able to publish the form, but it crashes whenever a user submits the form. It only seems to like 3 contact selectors. Any thoughts? Thanks so much!

Unknown said...

Odd that it should crash with more than three contacts. Did you remove the extra contact selector to find it not crashing no more? I.e. are you 100% sure that the fourth selector is causing the crash?