Getting the current row in code - InfoPath Dev
in

InfoPath Dev

Getting the current row in code

Last post 03-16-2007 01:36 PM by Greg Collins. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 03-15-2007 07:59 AM

    Getting the current row in code

    Hi,

    I have a repeating table with an "on changed" event handler for one of the fields in the table. Whenever the value changes, I want to modify the value of a different field in the same row. How can I reference a different field of the current row? (This needs to work in a browser-enabled form, if that makes any difference.) Thanks in advance!
  • 03-15-2007 09:54 AM In reply to

    Re: Getting the current row in code

    Use a relative XPath... you should already have the object for the current node from the event handler parameters. Then you can use a relative XPath like "../OtherField" to get to the other field. The .. means to go up to the parent node.
  • 03-15-2007 10:26 AM In reply to

    Re: Getting the current row in code

    The "field" that changes is actually an attribute within a node of an XmlDocument which is the datasource passed back from a web service. This attribute is the "sender" object when the "on changed" event fires. The other "field" that I need to update within the event handler is a different attribute of the same Xml element.

    I tried "./@otherattribute" as the path for a SelectSingleNode on the datasource, but it complains of a null reference exception.

    I think I'm having problems because the sender is just an attribute instead of a node. When I examine the XmlEventArgs it says that the OldParent is null.

    I wonder if using the current() function my path might work better? I tried something like that, but it complained that it needs an XSLT context.
  • 03-15-2007 02:06 PM In reply to

    Re: Getting the current row in code

    If your particular scenario current() is the same as ., so there's no advantage.

    Did your XPath use "./" or "../"? Because that makes a difference. As stated above "." is the current node whereas ".." is the parent node (even for attributes).
  • 03-15-2007 02:48 PM In reply to

    Re: Getting the current row in code

    Both "./" and "../" returned null references. Current() doesn't appear to be allowed in XPath expressions. It says it's an undefined function and asks for an XsltContext to provide a definition. I had hoped to be able to use current() in the context of an absolute XPath. Something along the lines of
    "/dfs:myFields/dfs:dataFields/...record[current()]/@otherattribute"
    I know there is a current() function in InfoPath, but I don't know how to get it to work in the code of an event handler.

    This is getting pretty frustrating - it should be simple. This is a project with high visibility in the company and I'm at a complete standstill. Argh!
  • 03-15-2007 10:56 PM In reply to

    Re: Getting the current row in code

    Have you tried just using a rule on the field in your form. When it changes it sets the value of the other form in the row? This might be a good work around solution until you get your syntax figured out. Since you are changing a field in the same row you do not have to use the current function. Typically it is a syntax issue in your xpath statement.

    Good Luck
  • 03-16-2007 06:16 AM In reply to

    Re: Getting the current row in code

    Thanks for your response.

    I looked at using a rule. The problem with that approach is that the conditions on when to apply a rule appear to be limited to <some value> "is equal to" or "is not equal to" or "is less than" etc. <some other value>. I would need the rule to apply whenever the value is *changed*, regardless of how it compares to some other value or whether it matches a specific pattern. Also, I don't want to execute the rule if the value hasn't changed. None of the rule options seem to allow for this.
  • 03-16-2007 09:34 AM In reply to

    Re: Getting the current row in code

    That confused me the first time I saw it too. The solution is to NOT use a condition. If there is no condition present on the rule, then it DOES fire each time a value is changed.
  • 03-16-2007 09:44 AM In reply to

    Re: Getting the current row in code

    YEA!! That worked! Thanks for sticking with me on this, Greg. Thanks for your input as well, Clay. This should be documented somewhere...

    Myles
  • 03-16-2007 01:36 PM In reply to

    Re: Getting the current row in code

    Actually it kind of is--if you look at the rule dialog box, it says:

    Condition:
    None - This rule always applies.

    Now, you might not understand exactly what that means right away--but I'm sure it makes total sense to you know that you've been through this!

    Keep up the good work!
Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.