XPath and eval() - InfoPath Dev
in

InfoPath Dev

XPath and eval()

Last post 09-12-2006 12:25 PM by jrshrenk. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 09-08-2006 10:25 AM

    • jrshrenk
    • Not Ranked
      Male
    • Joined on 08-15-2006
    • Phoenix, AZ
    • Posts 4

    XPath and eval()

    Hello,

    First off, many thanks to the site maintainers and InfoPath experts who have already (unknowingly) helped me on dozens of issues that I've had so far. These forums and tutorials are invaluable.

    That said, I have come across an issue that I'm afraid I've run out of resources to try to fix. Here's the setup:

    I have a repeating table that keeps a list of individuals (and is used throughout the form). On one view, the form user is asked to assign each individual to one square in a nine square box (via radio button). I have then been asked to create a print view of that nine square box that lists out the names of the individuals assigned to each of the boxes. Each of those names should be a separate line.

    Based on http://blogs.msdn.com/infopath/archive/2006/04/05/569338.aspx, I have managed to get as far as creating a list of all individuals. My next step is to filter the full list of individuals and display only those individuals that were selected for the single square.

    In a text box, I have the following code (which does not filter at all):

    xdMath:Eval(xdMath:Eval(../my:associates/my:individual, 'concat(my:profile/my:name, xdXDocument:GetDOM("characters")/characters/@cr)'), "..")

    In order to filter, I used the following:

    xdMath:Eval(xdMath:Eval(../my:associates/my:individual[my:profile/my:matrix_assignment_code = 'kc'], 'concat(my:profile/my:name, xdXDocument:GetDOM("characters")/characters/@cr)'), "..")

    This causes an error:

    quote:
    MSXML5.DLL
    Reference to undeclared namespace prefix: 'my'.


    Error occurred during a call to property or method 'Eval'.


    If I remove the "kc" and simply have it check for the existance of the node (or that it is empty), the formula verifies properly, but of course, it no longer filters the names as required.

    So the question.... is what I need to do possible with the way I'm using eval()? It seems like eval() places some restrictions on how filtering can be done (or it's just buggy--but I would never presume). Alternatively, should I just use code to do this and quit trying to turn a text box into a nuclear reactor?

    Any suggestions or explanations would be helpful. Thanks!
  • 09-10-2006 11:30 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694
    Hi jrshrenk,

    Eval function returns the values of a set of fields. The first argument defines the set of fields; the second argument defines the expression to calculate for the set of fields. Usually, the eval function is nested within a function that operates on a set of fields, such as sum or avg.

    In your XPath:
    xdMath:Eval(xdMath:Eval(../my:associates/my:individual[my:profile/my:matrix_assignment_code = 'kc'], 'concat(my:profile/my:name, xdXDocument:GetDOM("characters")/characters/@cr)'), "..")

    Can you check with second eval function works correctly or not then you need to test first eval function. Because of we can find out which function is works correctly.
  • 09-11-2006 07:15 AM In reply to

    • jrshrenk
    • Not Ranked
      Male
    • Joined on 08-15-2006
    • Phoenix, AZ
    • Posts 4
    Hi Shiva,

    It is the inner Eval() that is causing errors. Here's the edited XPath. It creates the same error:

    xdMath:Eval(../my:associates/my:individual[my:profile/my:matrix_assignment_code = 'kc'], 'concat(my:profile/my:name, xdXDocument:GetDOM("characters")/characters/@cr)')

    Nonetheless, as a curiosity, I removed the kc from the XPath and it returns no errors (but also will not accomplish my goal.

    Thoughts?

    James
  • 09-11-2006 11:15 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694
    Hi James,

    You need to test above two Xpath's are correct or not.
    1. You need to confirm first xpath is “../my:associates/my:individual[my:profile/my:matrix_assignment_code = 'kc']”. You need to try this xpath in some other text box or same text path is it giving value or not.
    2. You need to test second xpath is “concat(my:profile/my:name, xdXDocument:GetDOM("characters")/characters/@cr)”.

    Then above two cases is correct then Eval function also gives the correct value.
  • 09-11-2006 04:59 PM In reply to

    • jrshrenk
    • Not Ranked
      Male
    • Joined on 08-15-2006
    • Phoenix, AZ
    • Posts 4
    Hi Shiva,

    Here are the results of breaking up the statements:

    ../my:associates/my:individual[my:profile/my:matrix_assignment_code = 'kc']

    The statement above validates without any problem.

    concat(my:profile/my:name, xdXDocument:GetDOM("characters")/characters/@cr)

    This statement did not immediately validate (I believe it lost the context node). I changed it to:

    concat(../my:associates/my:individual/my:profile/my:name, xdXDocument:GetDOM("characters")/characters/@cr)

    ... and it validated correctly. Upon combining the two back into the Eval() function, it gave the same MSXML5.DLL errors indicating the same "undeclared namespace prefix my:".
  • 09-12-2006 12:25 PM In reply to

    • jrshrenk
    • Not Ranked
      Male
    • Joined on 08-15-2006
    • Phoenix, AZ
    • Posts 4
    Resolved:

    I ended up just going the code route. I used a for loop to loop through each individual and pick up their matrix_assignment_code. Within the for loop is a switch/case structure that concatenates the fields I need. Outside the for loop I then assign each variable to a different input box.

    This ends up working out better as it properly interprets \n as a new line in the text box and I get to skip over the extra XML file for ASCII codes.

    Here's the code for those interested:

    function popBox() {

    var total_rows = XDocument.DOM.selectSingleNode("/my:allTeams/my:myTeam/my:associates/my:assoc_count").text;
    var sq_kc = ""
    for ( var i = 1; i <= total_rows; i++ ) {
    var getCurrent = i
    var node = "/my:allTeams/my:myTeam/my:associates/my:individual[" + getCurrent + "]/my:profile/my:name";
    var r = XDocument.DOM.selectSingleNode(node).text;
    var node2 = "/my:allTeams/my:myTeam/my:associates/my:individual[" + getCurrent + "]/my:profile/my:matrix_assignment_code";
    var s = XDocument.DOM.selectSingleNode(node2).text;
    var node3 = "/my:allTeams/my:myTeam/my:associates/my:individual[" + getCurrent + "]/my:profile/my:title";
    var t = XDocument.DOM.selectSingleNode(node3).text;
    switch(s) {
    case "kc": sq_kc += i + r + " -- " + t + "\n"; break;
    case "ap1": sq_kc += i + r + " -- " + t + "\n"; break;

    ...

    default: break;
    }
    }
    var kcNode = "/my:allTeams/my:myTeam/my:kc";
    var kcVal = XDocument.DOM.selectSingleNode(kcNode);
    kcVal.text = sq_kc;
    }


    Thanks for your help Shiva! I ultimately just needed to give up on the direction I was trying to go (even though I felt like it was so close to working).

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