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

We have a form that we've built using InfoPath 2010 that will publish to a SharePoint 2010 site. We would like to have the form check against the list when a user enters a unique value in a field (such as an employee ID #) and return any data associated with that ID if it finds any and pre-populate form fields. So, for example, let's say John Smith went and filled out this form today. He enters his ID at the first page and hits 'Submit'. The form would check against the list column of ID to see if his is there. Since he hasn't come here before there isn't a record yet. So he goes through and fills out the fields of the form and submits it. A month later, he forgets if he filled in a field or not and comes back to the first page that he has to enter his ID. After he enters it and hits 'Submit' the form again queries the list and finds his previous submission and pre-populates the fields on the next page. He can then change or add data and submit. Hopefully, it would just update that existing record instead of creating a new one but that's a 'nice-to-have'. Any ideas or help would be greatly appreciated! Thank you!

share|improve this question
    
Is the lookup list on the same site collection? –  andrew.petersen15 Nov 16 '12 at 21:45
    
Yes. I believe so. –  David Lender Nov 16 '12 at 22:20
add comment

1 Answer

up vote 0 down vote accepted

This is certainly do-able, but this question is rather broad. Basically, when you query against the ID, if you get results back you would set a boolean that you would maintain. When the user actually submits the form, if the boolean is set to say that a list item was found you would update the list item, otherwise you would create a new list item.

You'll want to get familiar with CAML queries. A query against a UserID list column, for instance, would look like:

string userID = GetTheUserID();
SPList list = GetYourList();

SPQuery myQuery = new SPQuery();
myQuery.Query = "<Where>" +
                  "<Eq>" +
                    "<FieldRef Name='UserID' />" +
                    "<Value Type='Text'>" + userID + "</Value>" +
                  "</Eq>" +
                "</Where>";
SPListItemCollection returnedData = list.GetItems(myQuery);

Let me give you a few links to get you started here:

CAML Query Schema

Introduction to Programming in InfoPath 2010

share|improve this answer
    
Thanks rjcup3! We'll look into it and let you know if we need more help or if we get it to work. Thanks again! –  David Lender Nov 21 '12 at 14:51
add comment

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.