How to display the right value, given a code entered b a user? - InfoPath Dev
in

InfoPath Dev

How to display the right value, given a code entered b a user?

Last post 03-16-2010 11:59 PM by MasterXPath. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-16-2010 07:03 AM

    How to display the right value, given a code entered b a user?

    I'm trying to display a value given a code entered by a user.

    Since I work with InfoPath 2007, it just support xPath 1.x, so to create a simple if-statement I constructed a rule like this:

    substring(Value1, 1, (. = Code) * string-length(Value1)) // Value1 and Code is from a secondary datasource this secondary datasource is an XML "codelist" which should help me map a zipcode to a cityname. Code = 1234 => Value1 = New York

    This xPath-expression, rule, on one field do set a value in another field. In the first field a user types a zip-code, which should end up as a cityname in the second field.

    My codelist would then be so that Code[1] = 1234, Value1[1] = New York; Code[2] = 4321, Value1[2] = Miami;

    The xPath expression above does find the code value, i.e. if I type "1234" in the first field the second field displays "New York". I guess it is able to find out that there actually is a code-node containing "1234". If I type "4321" I would like the second field to display "Miami", but i still displays "New York". I guess it is able to find out that there is a Code-node containing "4321", but it wrights the wrong Value1-node. (If I type a number that does not exist in the list it displays nothing, which is correct...)

    How to get the right Value1-node????

  • 03-16-2010 07:21 AM In reply to

    Re: How to display the right value, given a code entered b a user?

    I don't think you want to use substring here.  All you need is a simple XPath selection formula:

     /DataSource/Value[Code = current()]

    Or something along those lines.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-16-2010 11:59 PM In reply to

    Re: How to display the right value, given a code entered b a user?

    /DataSource/Value[Code = current()] sounds ok, but does not work.

    I have tryed this, but then it dosn't wright anything at all in the secong field.

    What I need to know i what instance of Code that is equal to the first field. And then have /DataSource/Value["instance of Code which = First field"]

    How do I get to know which instance of Codethat equals my first field?

    Edit:

    My XML looks like this:

    <CodeListRows>
      <CodeListRow>
        <Code>1234</Code>
        <Value1>New York</Value1>
      </CodeListRow>
      <CodeListRow>
        <Code>4321</Code>
        <Value1>Miami</Value1>
      </CodeListRow>
      ....
    <CodeListRows>

    What I want is to wright "Miami" in a textbox, when a user types 4321 in my inpufield. As said I do find the right code. I don't get to wright Miami, but always get New York. If user types 1234 I get New York (correct), If user types 4321 I get New York (wrong, should have been Miami), If user types 9999, I get nothing (correct).

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