Submit Button Code Error - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Submit Button Code Error

Last post 05-07-2013 06:50 AM by Jim Shorts. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-03-2013 01:00 PM

    Submit Button Code Error

    Hi, I have coded a button in my IP2010 Library Form that will iterate through a repeating table and a repeating section and submit those values together line by line to a list in SP2010.  However, after multiple attempts to update and fix the code, I get the following error:

    "Business logic failed due to an exception. (User: User_ID, Form Name: InfoPath Template, IP: , Request: http://SharePoint/My_Site> , Form ID: urn:schemas-microsoft-com:office:infopath:InfoPath-Template:-myXSD-2013-04-16T13-50-05, Type: NullReferenceException, Exception Message: Object reference not set to an instance of an object.) 6e8fff27-0da7-4cac-bcf2-1b4931687c1d
    05/03/2013 10:44:59.42 w3wp.exe (0x0B14) 0x3F4C InfoPath Forms Services Runtime - Business Logic 7tge Medium Exception thrown from business logic event listener: System.NullReferenceException: Object reference not set to an instance of an object. at InfoPath_Template.FormCode.Submit(Object sender, ClickedEventArgs e) at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.<>c__DisplayClass6.<>c__DisplayClassa.<add_Clicked>b__3() at Microsoft.Office.InfoPath.Server.Util.DocumentReliability.InvokeBusinessLogic(Thunk thunk) at Microsoft.Office.InfoPath.Server.SolutionLifetime.ButtonEventHost.FireClickedEvent(Document document, ClickedEventArgs args) at Microsoft.Office.InfoPath.Server.DocumentLifetime.OMExceptionManager.CallFormCodeWithExceptionHandling(UserMessages userMessages, OMCall d) 6e8fff27-0da7-4cac-bcf2-1b4931687c1d"

    Here is the code:

    public void InternalStartup()
            {
                  ((ButtonEvent)EventManager.ControlEvents["CTRL277_5"]).Clicked += new ClickedEventHandler(Submit);
            }
    public void Submit(object sender, ClickedEventArgs e)
            {
                using (SPSite site = new SPSite("http://SharePoint/MySite")) //SPContext.Current.Site
                {
                    if (site != null)
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            web.AllowUnsafeUpdates = true;
                            SPList fetchlist = web.Lists["My List"];
                            if (fetchlist != null)
                            {
                                // Retrieve the rows of the repeating table
                                XPathNavigator root = MainDataSource.CreateNavigator();
                                XPathNodeIterator rows = root.Select("/my:myFields/my:dataFields/my:repeatingGroup", NamespaceManager);
                                XPathNodeIterator rows1 = root.Select("/my:myFields/my:dataFields/my:repeatingSection", NamespaceManager);
                                while (rows.MoveNext())
                                {
                                    // Retrieve the title
                                    string title = rows.Current.SelectSingleNode("my:FieldName", NamespaceManager).Value;
                                    if (title != string.Empty)
                                    {
                                        //string fieldValue1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:dataFields/my:repeatingGroup/my:FieldName", NamespaceManager).Value;
                                        string fieldValue1 = rows.Current.SelectSingleNode("my:FieldName", NamespaceManager).Value;
                                        string fieldValue2 = rows.Current.SelectSingleNode("my:FieldType", NamespaceManager).Value;
                                        string fieldValue3 = rows.Current.SelectSingleNode("my:Location", NamespaceManager).Value;
                                        string fieldValue4 = rows.Current.SelectSingleNode("my:UserID", NamespaceManager).Value;
                                        string fieldValue5 = rows.Current.SelectSingleNode("my:CurrentDate", NamespaceManager).Value;
                                        string fieldValue6 = rows.Current.SelectSingleNode("my:NewDate", NamespaceManager).Value;
                                        string fieldValue7 = rows.Current.SelectSingleNode("my:AlternateDate", NamespaceManager).Value;
                                        string fieldValue8 = rows.Current.SelectSingleNode("my:NewStatus", NamespaceManager).Value;
                                        string fieldValue9 = rows1.Current.SelectSingleNode("my:FirstReason", NamespaceManager).Value;
                                        string fieldValue10 = rows1.Current.SelectSingleNode("my:SecondReason", NamespaceManager).Value;
                                        string fieldValue11 = rows1.Current.SelectSingleNode("my:ThirdReason", NamespaceManager).Value;
                                        string fieldValue12 = rows1.Current.SelectSingleNode("my:FinancialInformed", NamespaceManager).Value;
                                        string fieldValue13 = rows1.Current.SelectSingleNode("my:NewNotice", NamespaceManager).Value;
                                        string fieldValue14 = rows1.Current.SelectSingleNode("my:AssociateRegion", NamespaceManager).Value;
                                        string fieldValue15 = rows1.Current.SelectSingleNode("my:PrimaryReason", NamespaceManager).Value;
                                        string fieldValue16 = rows1.Current.SelectSingleNode("my:SecondaryReason", NamespaceManager).Value;
                                        string fieldValue17 = rows.Current.SelectSingleNode("my:NewFieldType", NamespaceManager).Value;
                                        SPListItem newitem = fetchlist.AddItem();
                                        newitem["Field_x0020_Name"] = fieldValue1;
                                        newitem["Field_x0020_Type"] = fieldValue2;
                                        newitem["Location"] = fieldValue3;
                                        newitem["User_x0020_ID_x003a_ID"] = fieldValue4;
                                        newitem["Current_x0020_Date"] = fieldValue5;
                                        newitem["New_x0020_Date"] = fieldValue6;
                                        newitem["Alternate_x0020_Date"] = fieldValue7;
                                        newitem["New_x0020_Status"] = fieldValue8;
                                        newitem["First_x0020_Reason"] = fieldValue9;
                                        newitem["Second_x0020_Reason"] = fieldValue10;
                                        newitem["Third_x0020_Reason"] = fieldValue11;
                                        newitem["Finance_x0020_Informed_x0020_of_"] = fieldValue12;
                                        newitem["New_x0020_Notice"] = fieldValue13;
                                        newitem["Associate_x0020_Region"] = fieldValue14;
                                        newitem["Primary_x0020_Reason_x"] = fieldValue15;
                                        newitem["Secondary_x0020_Reason"] = fieldValue16;
                                        newitem["New_x0020_Field_x0020_Type"] = fieldValue17;
                                        newitem.Update();
                                    }
                                    
                                }
                                                            
                                web.AllowUnsafeUpdates = false;
                            }
                        }
                      
                    }
                }
                
              
            }
    Also, I do have two nodes on my main data connection that I'm trying to send to the same line on the same list, one being a repeating section, the other a repeating table.  Not sure if this has anything to do with the error. Thanks in advance for any help!
    Filed under: , ,
  • 05-07-2013 06:50 AM In reply to

    Re: Submit Button Code Error

    I set the second node as a static section and am only looping through the the first node.  Seems to have done the trick.

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