InfoPath 2013 browser form - a secondary data source loads the list of items that will be updated (changed) on an 'On After Change Event'. It is only changing the value of the 'Status' column in every row where the value was changed.
The code below is not updating the list ... what am I doing wrong? I have checked and rechecked the names of the list and the data connection.
// Start Event
public void AmendTenantRent__Status_Changed(object sender, XmlEventArgs e)
{
if (e.Operation == XmlOperation.ValueChange)
{
if (e.Site.Name == "Status" && e.OldValue != e.NewValue)
{
// Get the ID of the item to be changed
int id = Int32.Parse(e.Site.SelectSingleNode(
"../@ID", NamespaceManager).Value);
// Get the connection to the secondary data source SharePointListQueryConnection conn =
SharePointListRWQueryConnection spConnection = (SharePointListRWQueryConnection)this.DataConnections["AmendTenantRent"];
Uri siteUri = spConnection.SiteUrl;
// Update the SharePoint list item
using (SPSite site = new SPSite(siteUri.AbsoluteUri))
{
if (site != null)
{
using (SPWeb web = site.OpenWeb(siteUri.AbsolutePath))
{
SPList list = web.GetList(
siteUri.AbsolutePath + "Lists/TenantRent");
if (list != null)
{
SPListItem item = list.GetItemById(id);
if (item != null)
{
item["Status"] = e.NewValue;
web.AllowUnsafeUpdates = true;
item.Update();
web.AllowUnsafeUpdates = false;
}
}
web.Close();
}
}
site.Close();
}