Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
In the end I created a sharepoint group and used the standard person picker. It allowed that form to remain without any code. –  gordatron Feb 23 '13 at 10:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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