Setting the value of a node - InfoPath Dev
in

InfoPath Dev

Setting the value of a node

Last post 07-27-2006 12:43 PM by Greg Collins. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-25-2006 03:28 PM

    Setting the value of a node

    Hi,

    I am new to InfoPath coding and currently use JScript and Microsoft Script Editor environment to create some simple scripts for software test tracking.

    To date I have picked up quite a few hints on this forum that has helped me immensely. One of the problems I am facing currently is being able to update the value of a node in an infoPath Schema by using JScript Code.

    I am using InfoPath forms to create Test Scripts and track their execution & results. Each script has a number of test steps and as the testers execute the scritps they record Pass/Fail against each step and then record a defect id against the specific row. At the end when the tester clicks the submit button, I have the form save a copy to a Test Execution library and publish some of the form values in the list - such as Test Script name, date executed, tester, final outcome, All Defect IDs.

    It is with publishing all Defect IDs that I am facing a problem. The Form XML Structure is something like this.

    <Test Case Name>
    <Test Header Information>
    [Series of nodes to capture execution date, tester, final result, All Defects, etc]
    <Test Script Steps> 1..* rows depending on the number of steps
    <StepNum> [Auto number]
    <Condition and Action> [Rich Text Field]
    <Expected Result> [Rich Text Field]
    <Result> [Combo - Pass / Fail]
    <Defect ID> [Text string]


    The code below is executed when I click on a button to "Get all defects". This is done before sumbitting the result.

    This script works fine until it has to update the value of the All Defects node with the concatenated values of the available defect ids in each failed step.

    I do not know which XML method to use to update the value of the AllDefectIDs node.

    quote:
    //This function concatenates all Defect IDs in the form
    function btnGetDefectIDs::OnClick(eventObj)
    {
    // Write your code here

    var numRows, currRow ; // integer
    var objRepeatingTable ; // XML of document
    var nodeAllDefects ; // For AllDefects
    var nodeTestExecutionSummary ; // For TestExecutionSummary
    var currDefectID, allDefectIDs ; // strings for defect ids

    // initialise values
    allDefectIDs = "";


    objRepeatingTable = XDocument.DOM.selectNodes( "/my:TestCaseDocument/my:TestCaseSteps/my:TestCaseTable");
    numRows = objRepeatingTable["length"];


    // Iterate through rows and get Defect IDs
    for (currRow = 1; currRow <= numRows; currRow++)
    {
    currDefectID = (XDocument.DOM.selectSingleNode("//my:TestCaseTable["+ currRow +"]/my:DefectID").text)
    if (currDefectID != "")
    {
    if (allDefectIDs == "")
    allDefectIDs = currDefectID ; // for first defect only
    else
    allDefectIDs = allDefectIDs + "," + currDefectID ; // for all other defects
    }
    }


    //Debug - Display all defects
    XDocument.UI.Alert("Value of Defects = " + allDefectIDs);


    //Set Value of AllDefects Node
    nodeAllDefects = XDocument.DOM.selectSingleNode("/my:TestCaseDocument/my:TestExecutionSummary/my:AllDefects");
    nodeAllDefects.setAttributeNode(allDefectIDs); // <-- Unable to set value of Node here

    XDocument.UI.Alert("AllDefects value has been set!");

    } // end of btnGetDefectIDs


    Any advise will be greatly appreciated.

    Thanks
    Nara
    Thanks
    Nara Chilluvuri
  • 07-25-2006 04:41 PM In reply to

    Re: Setting the value of a node

    What attribute are you trying to set?

    Better way to set the attribute value is:

    attrAllDefects = XDocument.DOM.selectSingleNode("/my:TestCaseDocument/my:TestExecutionSummary/my:AllDefects/@my:attributeToSet");
    attrAllDefects.text = allDefectIDs;
  • 07-26-2006 02:29 PM In reply to

    Re: Setting the value of a node

    Hi Greg,

    Thanks tons for your help. Your suggestion did the trick. I was approaching this totally wrong having not worked with InfoPath too much before.

    In response to your question, I was trying to set the 'AllDefects' Attribute in the 'TestExecutionSummary' section. I realise I was mentioning the structure of the XML wrong and with the following modification it worked fine.

    attrAllDefects = XDocument.DOM.selectSingleNode("/my:TestCaseDocument/my:TestExecutionSummary/my:AllDefects");
    attrAllDefects.text = allDefectIDs;

    I should also thank your for all your other posts on this forum. I have used your suggestions on Auto numbering and couple of other tricks to get started in developing this InfoPath form.

    Cheers
    Nara


    quote:
    Originally posted by Greg Collins

    What attribute are you trying to set?

    Better way to set the attribute value is:

    attrAllDefects = XDocument.DOM.selectSingleNode("/my:TestCaseDocument/my:TestExecutionSummary/my:AllDefects/@my:attributeToSet");
    attrAllDefects.text = allDefectIDs;


    Thanks
    Nara Chilluvuri
  • 07-27-2006 12:43 PM In reply to

    Re: Setting the value of a node

    So glad I have helped. Keep up the good work. Perseverance pays off.
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.