I upload my infopath with code to sharepoint. Why it can't run code - InfoPath Dev
in

InfoPath Dev

I upload my infopath with code to sharepoint. Why it can't run code

Last post 01-13-2011 01:31 AM by MinkZzZzZzz. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-05-2011 09:24 PM

    I upload my infopath with code to sharepoint. Why it can't run code

     I create form Absence Request for leave employee in infopath sharepoint 2010.

    I create code connect to database for cal FromDate EndDate in holiday, my code is little bit ^^

    I read this site in http://ashrafhossain.wordpress.com/2010/08/30/publishing-administrator-approved-infopath-form-template-with-custom-code for upload template with code

    I do follow all step and complete !!
    But I don't know when I run form that have code, it can't run code me why ??

    However I debug code on infopath, it run code   = ="

    Help me,, please suggest !!

     

     

    My code

                XPathNavigator Form = this.MainDataSource.CreateNavigator();

                if (Form.SelectSingleNode("/my:myFields/my:FromDate", NamespaceManager).Value != "" && Form.SelectSingleNode("/my:myFields/my:EndDate", NamespaceManager).Value != "")
                {
                    DateTime fr = Form.SelectSingleNode("/my:myFields/my:FromDate", NamespaceManager).ValueAsDateTime;
                    DateTime en = Form.SelectSingleNode("/my:myFields/my:EndDate", NamespaceManager).ValueAsDateTime;


                  
                    SqlConnection MyConnection = new SqlConnection("Server=192.168.1.4;Database=HR;Trusted_Connection=True;");

                    //Find Holiday date
                    MyConnection.Open();
                    SqlCommand Cmd = new SqlCommand();
                    Cmd.Connection = MyConnection;
                    Cmd.CommandType = CommandType.Text;
                    Cmd.CommandText = "SELECT Count(*) HDate FROM Holidays where HolidaysDate between '" + fr + "' AND '" + en + "'";

                    SqlDataAdapter DA = new SqlDataAdapter(Cmd);
                    DataSet DS = new DataSet();
                    DA.Fill(DS);

                    string HoliCount = DS.Tables[0].Rows[0][0].ToString();

                    MyConnection.Close();


                    //Find Datediff

                    MyConnection.Open();
                    SqlCommand Cmd2 = new SqlCommand();
                    Cmd2.Connection = MyConnection;
                    Cmd2.CommandType = CommandType.Text;
                    Cmd2.CommandText = "select datediff(day,'" + fr + "','" + en + "')+1 as DateDD";

                    SqlDataAdapter DA2 = new SqlDataAdapter(Cmd2);
                    DataSet DS2 = new DataSet();
                    DA2.Fill(DS2);

                    string SelectLeave = DS2.Tables[0].Rows[0][0].ToString();

                    MyConnection.Close();


                    //


                    int TotalDayLeave = Convert.ToInt32(SelectLeave) - Convert.ToInt32(HoliCount);


                    Form.SelectSingleNode("/my:myFields/my:TotalDate", NamespaceManager).SetValue(TotalDayLeave.ToString());
                }

  • 01-11-2011 02:40 PM In reply to

    Re: I upload my infopath with code to sharepoint. Why it can't run code

    You may not have gotten any help yet because your post is a bit hard to understand. I think you are saying that you published your form as an admin approved template, but when opened in the browser, your code does not run. This same code works in client, however.

    If that is a correct assesment of your issue, are you getting any errors when you try to run your code in the browser? You may want to add some error handling to your code, like a try / catch statement, and set the value of a form field with the exception, so that you know what is failing.

    Hilary Stoupa

  • 01-13-2011 01:31 AM In reply to

    Re: I upload my infopath with code to sharepoint. Why it can't run code

    I run and find error follow picture


    So, I set

    Form.SelectSingleNode("/my:myFields/my:TotalDate", NamespaceManager).SetValue("1");
     
    It can run ..


    Help me !!!

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