-
buck_murdock
- Joined on 01-26-2009
- Posts 21
|
Contact Selector Within Repeating Section (Submit to SharePoint List)
I have a Ip form for software purchase requests. In this form i have a repeating sections with LicesendUser, LicensedPC, Software Title, and Software Price so that we can submit a form with multiple software titles for multiple people and keep track of who's ordered what. Using C# code i have gotten the form to submit to a SharePoint list properly, when it submits it uses the UpdateListItem Web service to create a new list row for each software title purchased. Each line shows who ordered what title and their contact information.
I added in the Contact Selector for the LicensedUser control so that all the names are entered in the same way each time. But now when i submit the form, it creates a new list item for each software title, but it keeps the LicensedUser information the same as the first one entered in the repeating table. I would like the LicensedUser column to preserve each persons name with the software title.
Here's the schema:
<my:rows> <my:row> <my:SoftwareTitle></my:SoftwareTitle> <my:SoftwarePrice xsi:nil="true"></my:SoftwarePrice> <my:OtherSoftwareTitle></my:OtherSoftwareTitle> <my:OtherSoftwarePrice xsi:nil="true"></my:OtherSoftwarePrice> <my:LicensedPC></my:LicensedPC> <my:OtherSoftwareCheck>false</my:OtherSoftwareCheck> <my:gpContactSelector> <my:Person> <my:DisplayName></my:DisplayName> <my:AccountId></my:AccountId> <my:AccountType></my:AccountType> </my:Person> </my:gpContactSelector> </my:row> </my:rows>
Here is my code (if any other information is useful let me know i'll get you whatever you need):
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.DirectoryServices;
using System.Web;
using System.Windows.Forms;
using System.IO;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.InfoPath.SemiTrust;namespace Software_Request_Form_Rev2
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }
// NOTE: The following procedure is required by Microsoft Office InfoPath.// It can be modified using Microsoft Office InfoPath.
public void InternalStartup()
{ ((ButtonEvent)EventManager.ControlEvents["SubmitButton"]).Clicked += new ClickedEventHandler(SubmitButton_Clicked);EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
} public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
try
{
// Get the user name of the current user.string userName = this.Application.User.UserName;
// Create a DirectorySearcher object using the user name
// as the LDAP search filter. If using a directory other
// than Exchange, use sAMAccountName instead of mailNickname.DirectorySearcher searcher = new DirectorySearcher(
"(mailNickname=" + userName + ")");
// Search for the specified user.SearchResult result = searcher.FindOne();
// Make sure the user was found.if (result == null)
{ MessageBox.Show("Error finding user: " + userName);
}
else
{
// Create a DirectoryEntry object to retrieve the collection
// of attributes (properties) for the user.DirectoryEntry employee = result.GetDirectoryEntry();
// Assign the specified properties to string variables.string FullName = (employee.Properties["displayName"].Value != null) ? employee.Properties["displayName"].Value.ToString() : "";
string Mail = (employee.Properties["mail"].Value != null) ? employee.Properties["mail"].Value.ToString() : "";string Location = (employee.Properties["physicalDeliveryOfficeName"].Value != null) ? employee.Properties["physicalDeliveryOfficeName"].Value.ToString() : "";
//Retrieve the Street Address from Active Directory and delimit to show only the mailstop number.string Address = (employee.Properties["streetAddress"].Value != null) ? employee.Properties["streetAddress"].Value.ToString() : "";
string searchKey = "MS";int searchKeyIndex = Address.IndexOf(searchKey);
string MailStop = Address.Substring(searchKeyIndex + searchKey.Length).Trim();string Phone = (employee.Properties["telephoneNumber"].Value != null) ? employee.Properties["telephoneNumber"].Value.ToString() : "";
string Department = (employee.Properties["department"].Value != null) ? employee.Properties["department"].Value.ToString() : "";
// Create an XPathNavigator to walk the main data source
// of the form.XPathNavigator xnMyForm = this.CreateNavigator();
XmlNamespaceManager ns = this.NamespaceManager;
// Set the fields in the form.xnMyForm.SelectSingleNode("/my:myFields/my:RequestorFullName", ns)
.SetValue(FullName); xnMyForm.SelectSingleNode("/my:myFields/my:RequestorEmail", ns)
.SetValue(Mail); xnMyForm.SelectSingleNode("/my:myFields/my:RequestorOffice", ns)
.SetValue(Location); xnMyForm.SelectSingleNode("/my:myFields/my:RequestorMailstop", ns)
.SetValue(MailStop); xnMyForm.SelectSingleNode("my:myFields/my:RequestorExtension", ns)
.SetValue(Phone); xnMyForm.SelectSingleNode("/my:myFields/my:RequestorDepartment", ns)
.SetValue(Department);
// Clean up.xnMyForm = null;
searcher.Dispose(); result = null;
employee.Close();
}
} catch (Exception ex)
{ MessageBox.Show("The following error occurred: " +
ex.Message.ToString()); throw;
}
} public void SubmitButton_Clicked(object sender, ClickedEventArgs e)
{
// Delete all Method nodes from the CAML Batch XMLXPathNavigator batch = DataSources["CustomListCAML"].CreateNavigator();
XPathNodeIterator iter = batch.Select("/Batch/Method");int methodNodesCount = iter.Count;
XPathNavigator firstMethodNav =batch.SelectSingleNode("/Batch/Method[1]",
NamespaceManager); XPathNavigator lastMethodNav =batch.SelectSingleNode("/Batch/Method[" + methodNodesCount.ToString() + "]",
NamespaceManager);
firstMethodNav.DeleteRange(lastMethodNav);
// Retrieve the rows of the repeating tableXPathNavigator root = MainDataSource.CreateNavigator();
XPathNodeIterator rows = root.Select("/my:myFields/my:rows/my:row", NamespaceManager);
// Retrieve the values for the custom list itemstring title = root.SelectSingleNode("my:myFields/my:title",
NamespaceManager).Value;
//Retrieve the RequestorFullName of the formstring RequestorFullName = root.SelectSingleNode("my:myFields/my:RequestorFullName",
NamespaceManager).Value;
//Retrieve the RequestorDepartment of the formstring RequestorDepartment = root.SelectSingleNode("my:myFields/my:RequestorDepartment",
NamespaceManager).Value;
//Retrieve the RequestorEmail of the formstring RequestorEmail = root.SelectSingleNode("my:myFields/my:RequestorEmail",
NamespaceManager).Value;
//Retrieve the AccountNumber of the formstring AccountNumber = root.SelectSingleNode("my:myFields/my:ChargeWorkTo",
NamespaceManager).Value;
//Retrieve the RequestorExtension of the formstring RequestorExtension = root.SelectSingleNode("my:myFields/my:RequestorExtension",
NamespaceManager).Value;
//Retrieve the OfficeLocation of the formstring OfficeLocation = root.SelectSingleNode("my:myFields/my:RequestorOffice",
NamespaceManager).Value;
//Retrieve the MailStop of the formstring MailStop = root.SelectSingleNode("my:myFields/my:RequestorMailstop",
NamespaceManager).Value;
// Loop through the rows of the repeating table
// and construct the CAML Batch XMLint counter = 1;while (rows.MoveNext())
{
// Retrieve the SoftwareTitlestring SoftwareTitle = rows.Current.SelectSingleNode(
"my:SoftwareTitle", NamespaceManager).Value;
// Retrieve the SoftwarePricestring SoftwarePrice = rows.Current.SelectSingleNode(
"my:SoftwarePrice", NamespaceManager).Value;
// Retrieve the LicensedPCstring LicensedPC = rows.Current.SelectSingleNode(
"my:LicensedPC", NamespaceManager).Value;
// Retrieve the LicensedUserstring DisplayName = rows.Current.SelectSingleNode("/my:myFields/my:rows/my:row/my:gpContactSelector/my:Person/my:DisplayName", NamespaceManager).Value;
// Add an item to the CAML Batch XML
AddMethodNode(counter, title, SoftwareTitle, SoftwarePrice, RequestorFullName, RequestorDepartment, RequestorEmail, AccountNumber, RequestorExtension, OfficeLocation, MailStop, LicensedPC, DisplayName);
// Increment the counter
counter++;
}
// Submit the Title of the requestbatch.SelectSingleNode("/Batch/Method/Field[@Name='Title']",
NamespaceManager).SetValue(title);
// Submit the rows to the Lists web service to update the custom listDataConnections["CustomListItemsSubmit"].Execute();
} private void AddMethodNode(int id, string title, string SoftwareTitle, string SoftwarePrice, string RequestorFullName, string RequestorDepartment, string RequestorEmail, string AccountNumber, string RequestorExtension, string OfficeLocation, string MailStop, string LicensedPC, string DisplayName)
{ System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendFormat( "<Method ID=\"{0}\" Cmd=\"New\">", id.ToString());sb.AppendFormat("<Field Name=\"Title\">{0}</Field>", title);
sb.AppendFormat( "<Field Name=\"SoftwareTitle\">{0}</Field>", SoftwareTitle);sb.AppendFormat("<Field Name=\"SoftwarePrice\">{0}</Field>", SoftwarePrice);
sb.AppendFormat( "<Field Name=\"LicensedPC\">{0}</Field>", LicensedPC);sb.AppendFormat("<Field Name=\"DisplayName\">{0}</Field>", DisplayName);
sb.AppendFormat( "<Field Name=\"RequestorFullName\">{0}</Field>", RequestorFullName);sb.AppendFormat("<Field Name=\"RequestorDepartment\">{0}</Field>", RequestorDepartment);
sb.AppendFormat( "<Field Name=\"RequestorEmail\">{0}</Field>", RequestorEmail);sb.AppendFormat("<Field Name=\"AccountNumber\">{0}</Field>", AccountNumber);
sb.AppendFormat( "<Field Name=\"OfficeLocation\">{0}</Field>", OfficeLocation);sb.AppendFormat("<Field Name=\"MailStop\">{0}</Field>", MailStop);
sb.AppendFormat( "<Field Name=\"PhoneNumber\">{0}</Field>", RequestorExtension);sb.AppendFormat("</Method>");XmlDocument methodXML = new XmlDocument();
methodXML.LoadXml(sb.ToString());
XPathNavigator batch = DataSources["CustomListCAML"].CreateNavigator();XPathNavigator batchNav = batch.SelectSingleNode("/Batch", NamespaceManager);
batchNav.AppendChild(methodXML.DocumentElement.CreateNavigator());
}
}
}
|
|