Hi guys! First post ever here on InfoPathDev.com :) I am an "intermediate" C++/C# developer, but this is my first time ever doing anything web-related. So I have a bunch of questions.
My end goal is to create an InfoPath form that will let users add records to a SharePoint list. There will be five or six fields. Some fields will be single lines of text, others will be lookup drop-downs that refer to elements in other SharePoint lists, and I'll also have a date picker.
I have successfully followed this MSDN InfoPath tutorial, which shows how to implement Submit functionality using CAML XML and C# code. It works great. But I have a ton of questions... :-P
For example, let's say I have the following fields:
- FirstName
- LastName
- Phone
- Email
- BranchLocation
Let's say that last field, BranchLocation, is a dropdown that connects to another SharePoint list that I have called Branches. I have no problem setting up that lookup, so when I click on the dropdown, I see a list of the five or six entries that I have in the Branches list.
The problem is, the plain-vanilla C# code in the example doesn't seem to work with lookup tables.
Here's the existing code, with another small section added to handle the BranchLocation:
// See if any new contacts have been added.
if (xiNewContacts.Count > 0)
{
while (xiNewContacts.MoveNext())
{
// Set the values in the Add List Item Template
// XML file using the values in the new row.
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Title']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Title", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='FirstName']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:FirstName", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='LastName']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:LastName", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Phone']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Phone", ns).Value);
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Email']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:Email", ns).Value);
// NEW CODE!!!!
// NEW CODE!!!!
// NEW CODE!!!!
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='BranchLocation']", ns)
.SetValue(xiNewContacts.Current.SelectSingleNode(
"my:BranchLocation", ns).Value);
// NEW CODE!!!!
// NEW CODE!!!!
// NEW CODE!!!!
// Set the values of the Changed and Delete columns to
// "FALSE".
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Changed']", ns)
.SetValue("FALSE");
xnCAML.SelectSingleNode(
"/Batch/Method/Field[@Name='Delete']", ns)
.SetValue("FALSE");
// Set the value of Cmd attribute to "New".
xnCAML.SelectSingleNode("/Batch/Method/@Cmd", ns)
.SetValue("New");
// Submit the new row.
wsSubmit.Execute();
}
}
When I try to run this, nothing happens. When I look at the contents of xnCAML, I can see that the <BranchLocation> tag in the CAML is set to the plain text value of the selected item in the BranchLocation drop down. Should that be an item index instead of a string?
Thanks!
--Peter