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!
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: