Not able to insert row with "Undefined" as error message - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Not able to insert row with "Undefined" as error message

Last post 04-22-2010 08:15 AM by vriyer. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 04-22-2010 08:15 AM

    • vriyer
    • Not Ranked
    • Joined on 04-14-2010
    • Posts 6

    Not able to insert row with "Undefined" as error message

    Hi

    I am trying to copy an secondary XML list from the SP into Main DOM.. I did the coding per the example I've seen from here using jscript.. The problem here is - I could see the variable value received from the list and it errors with a message "undefined" when it tries to insert.. Here is code I have.. Can someone please help?

    /*
     * This file contains functions for data validation and form-level events.
     * Because the functions are referenced in the form definition (.xsf) file,
     * it is recommended that you do not modify the name of the function,
     * or the name and number of arguments.
     *
    */

    // The following line is created by Microsoft Office InfoPath to define the prefixes
    // for all the known namespaces in the main XML data file.
    // Any modification to the form files made outside of InfoPath
    // will not be automatically updated.
    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-08T12:20:58" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
    //</namespacesDefinition>


    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======
    function CTRL786_45::OnClick(eventObj)
    {

     // Get the Project Id.
     var selectedType = XDocument.DOM.selectSingleNode("/my:myFields/my:Project/my:Summary/my:Proj_ID").text;

     // If no form was selected notify the user.
     if(selectedType == "")
     {
      XDocument.UI.Alert("Please enter a Project ID first.");
      return;
     }
     XDocument.UI.Alert("Project ID" + selectedType);
     
     // Get the list per the selected Project Id.
     var vehicles =XDocument.GetDOM("Phase_Metrics_XML").selectNodes("/ROWSETS/ROWSET1/ROW[PROJECT_ID = '" + selectedType + "']");

     // If nothing was found, then return; there will be no items to insert. 
     if(vehicles == null)
      return;
      
     // Get the insertion point.
     var vehicleList = XDocument.DOM.selectSingleNode("/my:myFields/my:Financial");

     // Add the rows to the main DOM.
     var vehicle;
     while(vehicle = vehicles.nextNode())
     {
      try
      {
       // Get the values from the secondary DOM.
       var phaseName = vehicle.selectSingleNode("PHASE_NAME").text;
       var phaseStart = vehicle.selectSingleNode("PHASE_START").text;
       var phaseFinish = vehicle.selectSingleNode("PHASE_FINISH").text;
       var phaseAct = vehicle.selectSingleNode("PHASE_ACT_COST").text;
       var phaseETC = vehicle.selectSingleNode("PHASE_ETC_COST").text;
       var phaseWeeks = vehicle.selectSingleNode("TOTAL_WEEKS").text;
       var phaseEstBurn = vehicle.selectSingleNode("TOTAL_BURN").text;
       var phaseActBurn = vehicle.selectSingleNode("ACTUAL_BURN").text;
       
       
       XDocument.UI.Alert("Vars " + phaseName);

       // Build a string representing a main DOM vehicle nodeset using the values from the secondary DOM.
       var vehicleXml = "<my:Phase_Detail xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-08T12:20:58'>"
           + "<my:Phase_Name>" + phaseName + "</my:Phase_Name>"
           + "<my:Phase_Start>" + phaseStart + "</my:Phase_Start>"
           + "<my:Phase_Finish>" + phaseFinish + "</my:Phase_Finish>"
           + "<my:Phase_Actuals>" + phaseAct + "</my:Phase_Actuals>";
           + "<my:Phase_ETC>" + phaseETC + "</my:Phase_ETC>";
           + "<my:Phase_Duration>" + phaseWeeks + "</my:Phase_Duration>";
           + "<my:Phase_Est_Burn>" + phaseEstBurn + "</my:Phase_Est_Burn>";
           + "<my:Phase_Act_Burn>" + phaseActBurn + "</my:Phase_Est_Burn>";
           
           
           
       vehicleXml += "</my:Phase_Detail>" ;

       // Load new vehicle string into a temporary XML DOM.
       var domNewRow = XDocument.CreateDOM();
       domNewRow.validateOnParse = false;
       domNewRow.async = false;
       domNewRow.loadXML(vehicleXml);
       domNewRow.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-08T12:20:58" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
       // domNewRow.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-08T12:20:58"');
       
       // Insert the new vehicle into the main DOM.
       vehicleList.appendChild(domNewRow.selectSingleNode("my:Vehicle"));
      }
      catch(ex)
      {
       XDocument.UI.Alert("Could not insert row.\n\nError message:\n" + ex.Message);
      }
     }
    }

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