Drop-Down listbox not decoding when setting the value

M

MattBell

I have a drop down list box which points to a webservice which I query on
form open. I have another section which populates the column automatically
but it only shows the code and not the description when I do a set value
rule. How do you make it only show the description?
 
B

Brian Teutsch [MSFT]

When you set the value of field2 to the dropdownField value, you will need
to use a filter to find the display value associated with the XML value.
This isn't too hard, as long as you start by using "Filter" on the dialog
where you chose to set field2 = dropdownField.

Brian
 
M

MattBell

Hey Brian thanks for the response,
I'm not sure I understand your suggestion however, are you saying place a
filter on my set value rule or on the field that is begin set?

In my form I have a column which represents State, it is a drop down list
box which uses the 2 letter state code as the code and the state name as it's
description. I set the value of the field to say "GA" and it appears as GA,
when I would really rather see Georgia.
So you are saying that when setting the state field to GA I put a filter on
that rule of somekind?
 
B

Brian Teutsch [MSFT]

Before I continue, I'm making an assumption that your dropdown list gets its
entries from a secondary data source. If you just typed them in, you won't
be able to do this.

If the entries are from a secondary data source, then you'll want to do the
following. When you set up the rule which sets field2 (textbox) to be equal
to field1 (dropdown), there is a dialog that lets you choose the field. That
dialog has a button called "filter" on it.

What you're going to now use to set field2's value is no longer field1, but
databaseField2 (the display value). But to get this right, you have to use
the filter button to select only databaseField2 where databaseField1 (the
dropdown's value) is equal to field1 (dropdown).

Now you are setting field2 = (databaseField2 (where databasefield1 =
field1) )

Hope that helps. It's not the simplest, but it is powerful.

Brian
 
B

Bill

Brian, thanks again for your response- I'm working with Matt on this project.

I guess there's some confusion. The problem is that we are trying to set the
value of the dropdown itself, not another text field (field2 in your
example). So what we're trying to do is have the dropdown, which is
populated with a bunch of state names (the description for the
dropdown)/state abbreviation (the value of the dropdown) pairs which do in
fact come from a secondary data source, get assigned a specific
name/abbreviation. Currently when I set the dropdown's value to be "GA",
"GA" shows up in the dropdown where I need to see "Georgia" (although the
value of the field needs to be the abbreviation). Does this make sense?

Thanks,
Bill
 
B

Bill

Thanks for the reply, but I think I described our setup poorly.

We have a webservice called GetStatesCode which returns an object that has a
code (the abbreviation) and the name (the longhand name of the state). Our
dropdown binding has GetStatesCode as the main lookup, code as the value, and
name as the displayed description (which I believe is what you're describing
below). The goal is to be able to have a rule from another view set the state
value to a code, but have the dropdown display the description which would
correlate to that code.

Thanks,
Bill
 
B

Bill

Thanks, that got us on the right track.

Just for those who may come after and have the same problem- you are
correct, there is in fact no trick. The problem was that the codes coming
back from our database were not stripped of trailing whitespaces, which
appears to have caused infopath to assume they were not the same and so
display our new, whitespace-trailing codes.

Thanks all for your help.

Bill

Greg Collins said:
So long as your drop-down is set up correctly (which it sounds like you have already done) to where the Value is 'code' and the Display Name is 'name', then you can set the 'code' from a rule from any view you want, and provided that it is a valid code, the correct name should appear in the drop-down list. This is assuming that your Data Source has already been populated via the Web service.

There shouldn't be any tricks to making the drop-down list display the right name. The only three things that should prevent this is:
1. Your drop-down list box isn't set up correctly (as described above).
2. You are setting a code that doesn't have a matching name defined in the data source.
3. Your data source has not yet been populated via the Web service.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



Thanks for the reply, but I think I described our setup poorly.

We have a webservice called GetStatesCode which returns an object that has a
code (the abbreviation) and the name (the longhand name of the state). Our
dropdown binding has GetStatesCode as the main lookup, code as the value, and
name as the displayed description (which I believe is what you're describing
below). The goal is to be able to have a rule from another view set the state
value to a code, but have the dropdown display the description which would
correlate to that code.

Thanks,
Bill

Greg Collins said:
Where are you binding your Value and Display Name to?

If you have a structure such as:

<State value="GA" name="Georgia">

You should your main lookup to "State" and not to "State/value"... you do this because then you can select "value" for the Value XPath and "name" for the Display Name XPath.

Chances are you see a dot "." in both the Value and Display Name fields... this is because you are binding to "State/value" instead of to "State".
 
Top