1

I have:

  • A Person Picker in an InfoPath form
    • Set to current user by default using SharePoint userprofileservice
  • A SharePoint List with a person column
    • this list is available in my InfoPath form as a datasource

I want to verify that a person selected is present in the list.

This can be done on submit or change of data in the Person Picker I don't mind.

The form is being submitted to a SharePoint form library and I do have options for creating a task in some way for an admin to clean up bad forms once they get there but I would like to avoid that.

(SharePoint & InfoPath 2010)

1

You can do that using code in the form. Find below how can be done.

var nav = this.MainDataSource.CreateNavigator();

//Obtain the Account Id from the people picker
var userId = nav.SelectSingleNode("my:myFields/my:RequesterGroup/pc:Person/pc:AccountId", NamespaceManager);

var web = SPContext.Current.Web;
var userList = web.Lists["YOUR LIST HERE"];

// Here I would use a CAML query instead, but works for the example
foreach (SPListItem item in userList.Items)
{
    var current = item["USER FIELD"] as SPFieldUserValue;
    var user = current.User;

    if(user.LoginName.equals(userId.Value))
    {
        // The user is part of the list, do something and return
    }
}

I hope it helps.

1
  • In the end I created a sharepoint group and used the standard person picker. It allowed that form to remain without any code. – user13635 Feb 23 '13 at 10:38

Your Answer

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