Auto-Populate Rules vs Code - InfoPath Dev
in

InfoPath Dev

Auto-Populate Rules vs Code

Last post 05-07-2007 01:27 PM by Tome. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-03-2007 03:08 PM

    • Tome
    • Not Ranked
      Male
    • Joined on 01-18-2007
    • USA
    • Posts 16

    Auto-Populate Rules vs Code

    Hi all,

    In a repeating section of my form I have a drop down box that lists materials. I use a rule to fill in the associated unit of measure based on the selected material. The rule uses the secondary data source I defined through "data connections". For some reason, the rule does not seem to consistantly fill in the correct value. I'm resorting to code based on the onAfterChange event of the materials dropdown.

    First question: What would cause the inconsistant behavior using the rule?

    Second question: I have code (below) to try and handle this but I can't seem to get the value from the secondary data source. Anyone have any suggestions?

    var objXMLNodes = XDocument.View.GetSelectedNodes();

    if (objXMLNodes.Count > 0)

    {

                    var sID = objXMLNodes(0).text;   //Grab the value of the selected dropdown          

                    //Get to the DOM

                    var doc = XDocument.DataObjects("Contract_Sub_Categories2_DC").DOM;

                    //Add the namespaces for the SelectSingleNodes

                    doc.setProperty("SelectionNamespaces", "xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");

                    //Get the selected node

                    var selectedNode = doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dsf:Contract_Sub_Categories2[@cs2ID='" + sID + "']")

                    //Set the form value

                    objXMLNodes(1).text = selectedNode.attributes.getNamedItem("cs2UOM").text

    }


    George Ball
    VeoliaES
    [email protected]
  • 05-03-2007 09:54 PM In reply to

    Re: Auto-Populate Rules vs Code

    As far as the inconsistency, my guess would be it is not always finding the value, when this occurs there is no warning or error it just will not do anything and have a blank result.  Typically what I found is that it is in the string matching, if there are any preceeding or trailing spaces or if one field is a var and the other not there can be space. I would look closely at a scenario where it is not working and check the strings being compared very closely.  The other issue sometimes could be duplicates and it returns the first which could maybe be incorrect.  This could work sometimes and not others depending on how the data source is being traversed.

    I will leave the code audit up to other experts but it could be having the same issue.

  • 05-04-2007 12:57 PM In reply to

    • Tome
    • Not Ranked
      Male
    • Joined on 01-18-2007
    • USA
    • Posts 16

    Re: Auto-Populate Rules vs Code

    What's weird about this is that sometimes it puts a value in the field and its just not the right one. If I open the secondary data source in MS Access I can see the correct information. That's why I'm trying to do it by code because I can't make sense of what the rules based approach is doing.

    George Ball
    VeoliaES
    [email protected]
  • 05-07-2007 10:17 AM In reply to

    • Tome
    • Not Ranked
      Male
    • Joined on 01-18-2007
    • USA
    • Posts 16

    Re: Auto-Populate Rules vs Code

    Ok, I'm now able to get the value from the secondary data source successfully and display it as an alert. Is there a way to get a reference to the current repeating row that fired the event so I can populate the correct field. I can only seem to populate the entry in the first row of the repeating table. This code is being run using an "OnAfterChange" event.

     

    var objXMLNodes = XDocument.View.GetSelectedNodes();

    var sID;

    if (objXMLNodes.Count > 0)

    {

    sID = objXMLNodes(0).text;

    var doc = XDocument.DataObjects("Contract_Sub_Categories2_DC").DOM;

    doc.setProperty("SelectionNamespaces", "xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields' xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");

    var selectedNode = doc.selectSingleNode("//dfs:myFields/dfs:dataFields/d:Contract_Sub_Categories2[@cs2ID=" + sID + "]");

    var struom = selectedNode.attributes.getNamedItem("cs2UOM").text;

    XDocument.UI.Alert(struom);

    }


    George Ball
    VeoliaES
    [email protected]
  • 05-07-2007 01:27 PM In reply to

    • Tome
    • Not Ranked
      Male
    • Joined on 01-18-2007
    • USA
    • Posts 16

    Re: Auto-Populate Rules vs Code

    Done. I found a different post that helped me put the value into the correct row of the repeating table. I posted the completed code below for anyone else.

     

    function msoxd__SR_Materials_cs2ID_attr::OnAfterChange(eventObj)

    {

    // Write code here to restore the global state.

          if (eventObj.IsUndoRedo)

                {

                      // An undo or redo operation has occurred and the DOM is read-only.

                      return;

                }

          var objXMLNodes = XDocument.View.GetSelectedNodes();

          var sID;

          if (objXMLNodes.Count > 0)

          {

                sID = objXMLNodes(0).text;  //Grab the value of the selected dropdown

                if (sID == "") //Check for actual value before querying

                {

                      return;

                }          

                //Get to the DOM

                var doc = XDocument.DataObjects("Contract_Sub_Categories2_DC").DOM;

                //Add the namespaces for the secondary data source

                doc.setProperty("SelectionNamespaces", "xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields' xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");

                //Find the node in the secondary data source

                var selectedNode = doc.selectSingleNode("//dfs:myFields/dfs:dataFields/d:Contract_Sub_Categories2[@cs2ID=" + sID + "]")

                //Grab the value from the node

                var struom = selectedNode.attributes.getNamedItem("cs2UOM").text;      

                //Put the value on the form

                eventObj.Site.selectSingleNode("../@uomCode").text = struom;

          }

    }


    George Ball
    VeoliaES
    [email protected]
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.