Update existing SharePoint List item using SharePoint Object Model - InfoPath Dev
in

InfoPath Dev

Update existing SharePoint List item using SharePoint Object Model

Last post 06-14-2013 04:14 PM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-11-2013 09:56 AM

    • GregE
    • Not Ranked
      Male
    • Joined on 06-12-2012
    • Norcross, GA
    • Posts 2

    Update existing SharePoint List item using SharePoint Object Model

     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();
         }

     

     

     

     

     

  • 06-14-2013 04:14 PM In reply to

    Re: Update existing SharePoint List item using SharePoint Object Model

     Is your form being used in a SharePoint 2013 site? You may want to write some debugging info to form fields in your code (since we can't just pop up a dialog from IPFS). Apparently, there are ways to attach to the process and run in debug from IPFS, but I've yet to manage to get that to work.

    Hilary Stoupa

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.