Creating a dataset before the form (xml) is saved. - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Creating a dataset before the form (xml) is saved.

Last post 09-24-2009 08:14 AM by golden_shiner. 15 replies.
Page 1 of 2 (16 items) 1 2 Next >
Sort Posts: Previous Next
  • 09-14-2009 01:16 PM

    Creating a dataset before the form (xml) is saved.

    Greetings,

    I am new in writting code for Infopath.  I have an infopath form for which I am writing some code in C# to check the data entered into it before the form is saved. In order to check that data I am trying to create a data set, but I don't know how since I dont have the file name to pass it to ReadXml(). Can someone PLEASE help me on how to go about doing this. Thank you very much in advance.

  • 09-14-2009 11:46 PM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    hi,

    if u r going to do it at savign time ,

    you can use folloiwing code to check the values

    XPathNavigator xntemp = null;

    XPathNavigator xnDoc = null;

    xnDoc = this.MainDataSource.CreateNavigator();

    xntemp = xnDoc.SelectSingleNode("/my:myFields/my:fieldToBeChecked", this.NamespaceManager);

    if ( xntemp.toString().equals("WhatEverYouWant"))

    {

    //write your code here

    }

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 09-15-2009 06:51 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    I appreciate the quick reply. Xpath was my first choice actually, but the reason I am using datasets is that I need to check values in repeating sections. The repeating section includes repeating rows and one single field  which are related and I need to check them that way. When I used Xpath all the rows (from all the repeating sections we accessed at the same time) which does not help me. So I need help in either reading each section seperately using Xpath or using ReadXml() by pointing to the current form. Thank You!!!

  • 09-15-2009 07:15 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    You should be able to use XPath to accomplish any validation that you need.  If you could provide a diagram of your data source and an example of what kind of validation you are trying to perform, one of us can show you an example of the sort of code to use.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-15-2009 07:57 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    ok, so the data source of this part of the form looks something like this:
    Repeating section:

     -Species Record
         Species_ID
            -Group_1mm
                -Group_1mm_sub
                       count  
                       length
                       weight
           -Group_1cm
               -Group_1cm_sub
                       count
                       length
                       weight

     For each specie I have to check the weight/length ratio and then I write out to a txt file if not correct ratio.
     

    The code below is what I have been using. the problem is, it goes through "count" length" "weight" for all the species. I need to check those values specie by specie so when I write out to the file I am ponting the  values to the right specie.
                     
      XPathNavigator myNav = MainDataSource.CreateNavigator();
      XPathNodeIterator NodeIterator = myNav.Select("/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:GROUP_1MM/my:GROUP_1MM_sub", NamespaceManager);

    while (NodeIterator.MoveNext())
                            {
                                myNode = NodeIterator.Current.CreateNavigator();
                                CountOneM = myNode.SelectSingleNode("my:COUNT_1MM", NamespaceManager).Value;
                                LengthOneM = myNode.SelectSingleNode("my:TOTAL_LENGTH_1MM", NamespaceManager).Value;
                                WeightOneM = myNode.SelectSingleNode("my:TOTAL_WEIGHT_1MM", NamespaceManager).Value;
                    }

    Thanks!

  • 09-15-2009 08:18 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    I'm still not sure exactly what the problem is.  Are you saying you don't have access to the Species ID when you find a weight/length ratio that violates the constraint?

    If so, you should be able to get at the current id within that while loop with something like:

    myNode.SelectSingleNode("../../my:Species_ID", NamespaceManager);

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-15-2009 10:09 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    The issue is that it always gives me the first specieID, it does not move to the next one.

  • 09-15-2009 10:25 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    Then something's not quite right with your code.  Could you attach an actual screenshot of your datasource, and the actual code you have tried so far, including the part to retrieve the specieID?
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-15-2009 11:36 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    XPathNavigator myNav = MainDataSource.CreateNavigator();

    XPathNodeIterator NodeIterator = myNav.Select("/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:GROUP_1MM/my:GROUP_1MM_sub", NamespaceManager);

    string species = String.Empty;

    string CountOneM = String.Empty;

    string LengthOneM = String.Empty;

    string WeightOneM = String.Empty;

    string BatchWeightOneM = String.Empty;

    double FinalLength = 0;

    double x = 0;

    double TempWeight = 0;

    double FinalWeight = 0;

     

    while (NodeIterator.MoveNext())

    {

     

    myNode = NodeIterator.Current.CreateNavigator();

    species = myNode.SelectSingleNode(
    "/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:SPECIES_ID", NamespaceManager).Value;

    CountOneM = myNode.SelectSingleNode("my:COUNT_1MM", NamespaceManager).Value;

    LengthOneM = myNode.SelectSingleNode("my:TOTAL_LENGTH_1MM", NamespaceManager).Value;WeightOneM = myNode.SelectSingleNode("my:TOTAL_WEIGHT_1MM", NamespaceManager).Value;

     

     

    switch (species)

    {

    case "139203":

     

    if (CountOneM == "" && LengthOneM != "" && WeightOneM != "")

    {

    DoWrite(
    "<p><strong>Missing number of fish</strong></p>");

    }

    else

    if (CountOneM != "" && LengthOneM != "" && WeightOneM == "")

    {

    DoWrite(
    "<p><strong>Missing Weight value</strong></p>");

    }   ......

     

    this is one of the ways I have tried to get species ID . Thank you again for the help.


  • 09-15-2009 12:43 PM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    The trouble is that you're using

     "/my:myFFIM_base_table/my:Species_Records/my:SpeciesGroup/my:SPECIES_ID"

    instead of

     "../../my:SPECIES_ID"

    like I suggested

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-15-2009 01:33 PM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    I am so sorry I missed that detail. BUT, it works as you suggested . THANK YOU VERY MUCH!!!!!!!!!  I am so releived, it was driving me crazy.

  • 09-17-2009 10:31 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    I have another question, how do I reference the values of COUNT_1CM, TOTAL_LENGTH_1CM under GROUP_1CM/group( in the data source shown above) before going to the next species ?? so basically running through all the 1mm 1cm and 2cm values before going to the next specie. Thank you very much for the help.  

  • 09-18-2009 07:43 PM In reply to

    Re: Creating a dataset before the form (xml) is saved.

     Just use relative XPath selection like in my earlier post.

    So visualizing that your XPathNavigator is positioned at the my:GROUP_1MM_sub node, you have to use ".." to move up several levels of the data source tree before going down again:

     XPathNavigator group1CM = myNode.SelectSingleNode("../../my:GROUP_1CM", NamespaceManager);

    The first .. refers one step up the tree to the GROUP_1MM node; the second refers another step up to the SpeciesGroup node, and then my:GROUP_1CM moves back down the tree again.

     Then you can from there continue going down the tree to get the values you want:

    XPathNavigator count1cm = group1CM.SelectSingleNode("my:group9/my:COUNT_1CM", NamespaceManager);

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 09-24-2009 06:45 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    Thank you for your reply. That seems to work except I can only access the values of the first row repeatedly. In other words it does run multiple times through the rows of data, but only gives me the values of the first row. Any ideas to why is that? Thank you very much.

  • 09-24-2009 07:17 AM In reply to

    Re: Creating a dataset before the form (xml) is saved.

    Would you mind sharing more of your code?  Without that, I can only repeat what I've said above.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 2 (16 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.