List values changing randomly..?

J

JR

I have a dropdown list in an Infopath form that has been giving me some grief; but I've managed to fix (or deal with) most of the problems. However, I'm running into a very odd situation.

I have a list pulling it's contents from an XML file. The file is on the same server as the Sharepoint site, but not part of the site itself - just in a publically accessible folder. Everything appears to be working properly, all the values appear in the list; but when a user selects an item in the list; a different item is actually selected/displayed. Also, it appears what is actually getting selected is random; because I can click on the same option in the list 4 times and get 4 different values.

Any ideas of what may cause this and how I go about fixing it?
 
S

Scott L. Heim [MSFT]

Hi JR,

I have not personally seen this behavior - maybe someone else has though. I
do have a couple of questions:

- Does the XML file contain duplicate entries?
- Is there a "unique" value field?
- Are you able to easily repro this? For instance, can you create a new,
blank InfoPath solution, take the same XML file as a data source and repro
the behavior? If so, can you provide a snippet of your XML file
structure/data and steps to repro?

Thanks JR,

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

JR

Hi again Scott;

Not all of the "values" are unique; although the display names are.

eg.

<Rate>
<Display>Item 1</Display>
<Value>6</Value>
</Rate>
<Rate>
<Display>Item 2</Display>
<Value>8</Value>
</Rate>
<Rate>
<Display>Item 3</Display>
<Value>6</Value>
</Rate>
...
 
S

Scott L. Heim [MSFT]

JR,

I think I am reproducing what you are seeing: when I bind a List Box
control to this XML file data connection, if I click on Item 1 it will
sometimes "jump" to Item 3 - is this what you are basically describing?

If so, then this would basically be expected. Let me explain: what is
important here for InfoPath is the "value" - not necessarily the Display
Name. So when you have duplicate values in the list, InfoPath is basically
just picking one of the items as it has no way to really know which one you
want.

The best solution to this is to add a unique field so you can "uniquely"
identify each of the items in the list. Even if it is just bringing those 2
fields together so you would have: Item16, Item28 and Item36 - you could
still display what you desire but the "Values" would be unique.

Does this help?

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

JR

Hi Scott;

I was afraid you'd say that.. The main issue is that the value is a number used in a mathematical calculation (a percentage multiplier in this case), so if I was to use your example below; how would I extract the number that I actually need?
 
S

Scott L. Heim [MSFT]

How does that number get calculated? From where does this XML file get its
data? It is updated on some basis?

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

JR

All the data comes from our Finance department. I have no idea how they arrive at the numbers but the percentage is somehow tied to the department. So realistically, the same value could exist for more than one department. I believe they will just manually update the file quarterly.
 
S

Scott L. Heim [MSFT]

Hi JR,

Sorry for the delay as I was unexpectedly out of the office.

See if these steps work in your scenario:

- Modify your sample XML file to the following:

<?xml version = "1.0" ?>
<Rates>
<Rate>
<Display>Item 1</Display>
<Value>6</Value>
<myKey>6-Item 1</myKey>
</Rate>
<Rate>
<Display>Item 2</Display>
<Value>8</Value>
<myKey>8-Item 2</myKey>
</Rate>
<Rate>
<Display>Item 3</Display>
<Value>6</Value>
<myKey>6-Item 3</myKey>
</Rate>
</Rates>

- Create a new, blank InfoPath solution
- Add a "Receive" data connection to the above referenced XML file named:
TestXML
- Add a drop-down list and text box to the form
- Right-click on the drop-down box and choose Properties
- Set the data connection of this control to: TestXML
- Click the Select XPath button next to Entries, select "Rate" and click OK
- Click the button next to Value Field, select myKey and click OK
- You can leave Display name as: Display
- Click OK to close this Property window
- Right-click on the text box control and choose Properties
- Click the "fx" button next to the Value field for the Default Value
- Click Insert Field or Group
- From the Data Source box choose: TestXML
- Drill down, highlight Value (under Rate) and click the Filter Data button
- Click Add
- From the first box, choose: myKey
- From the second box, choose: is equal to
- In the last box, choose: Select a field or group
- From the Data source box, choose: Main, highlight your drop-down list box
field and click OK
- Click OK 3 times to get back to the Insert Formula window - you should
basically see this: Value[myKey = field1]
- Modify this now to: Value[myKey = field1] * 10 (just to do some
mathematical function)
- Click OK 2 times to get back to your form
- Preview and test - you should be able to select any of the items in the
list and the result in the text box should change appropriately

Let me know if this works for you!!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

JR

Hi Scott;

That's working beautifully; it's fixed all the problems with the text box values changing; but it's cropped up one other slight issue. Until someone actually selects a value (and this is an optional field); the values calculated based on the DDL selection are all non-numbers (NaN).

This fouls up some of the other totals when this occurs. Is there a way I can force NaN values to be zero in the calculated fields if nothing is selected in the DDL or set a default selection from the DDL?

I've also noticed a blank entry in the DDL, is that by design?

Hi JR,

Sorry for the delay as I was unexpectedly out of the office.

See if these steps work in your scenario:

- Modify your sample XML file to the following:

<?xml version = "1.0" ?>
<Rates>
<Rate>
<Display>Item 1</Display>
<Value>6</Value>
<myKey>6-Item 1</myKey>
</Rate>
<Rate>
<Display>Item 2</Display>
<Value>8</Value>
<myKey>8-Item 2</myKey>
</Rate>
<Rate>
<Display>Item 3</Display>
<Value>6</Value>
<myKey>6-Item 3</myKey>
</Rate>
</Rates>

- Create a new, blank InfoPath solution
- Add a "Receive" data connection to the above referenced XML file
named:
TestXML
- Add a drop-down list and text box to the form
- Right-click on the drop-down box and choose Properties
- Set the data connection of this control to: TestXML
- Click the Select XPath button next to Entries, select "Rate" and
click OK
- Click the button next to Value Field, select myKey and click OK
- You can leave Display name as: Display
- Click OK to close this Property window
- Right-click on the text box control and choose Properties
- Click the "fx" button next to the Value field for the Default Value
- Click Insert Field or Group
- From the Data Source box choose: TestXML
- Drill down, highlight Value (under Rate) and click the Filter Data
button
- Click Add
- From the first box, choose: myKey
- From the second box, choose: is equal to
- In the last box, choose: Select a field or group
- From the Data source box, choose: Main, highlight your drop-down
list box
field and click OK
- Click OK 3 times to get back to the Insert Formula window - you
should
basically see this: Value[myKey = field1]
- Modify this now to: Value[myKey = field1] * 10 (just to do some
mathematical function)
- Click OK 2 times to get back to your form
- Preview and test - you should be able to select any of the items in
the
list and the result in the text box should change appropriately
Let me know if this works for you!!

Scott L. Heim
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no
rights.
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fprq2\fcha
rset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 Hi JR,
\par
\par Sorry for the delay as I was unexpectedly out of the office.
\par
\par See if these steps work in your scenario:
\par
\par - Modify your sample XML file to the following:
\par
\par <?xml version = "1.0" ?>
\par <Rates>
\par <Rate>
\par <Display>Item 1</Display>
\par <Value>6</Value>
\par <myKey>6-Item 1</myKey>
\par </Rate>
\par <Rate>
\par <Display>Item 2</Display>
\par <Value>8</Value>
\par <myKey>8-Item 2</myKey>
\par </Rate>
\par <Rate>
\par <Display>Item 3</Display>
\par <Value>6</Value>
\par <myKey>6-Item 3</myKey>
\par </Rate>
\par </Rates>
\par
\par - Create a new, blank InfoPath solution
\par - Add a "Receive" data connection to the above referenced XML
file named: TestXML
\par - Add a drop-down list and text box to the form
\par - Right-click on the drop-down box and choose Properties
\par - Set the data connection of this control to: TestXML
\par - Click the Select XPath button next to Entries, select "Rate"
and click OK
\par - Click the button next to Value Field, select myKey and click OK
\par - You can leave Display name as: Display
\par - Click OK to close this Property window
\par - Right-click on the text box control and choose Properties
\par - Click the "fx" button next to the Value field for the Default
Value
\par - Click Insert Field or Group
\par - From the Data Source box choose: TestXML
\par - Drill down, highlight Value (under Rate) and click the Filter
Data button
\par - Click Add
\par - From the first box, choose: myKey
\par - From the second box, choose: is equal to
\par - In the last box, choose: Select a field or group
\par - From the Data source box, choose: Main, highlight your
drop-down list box field and click OK
\par - Click OK 3 times to get back to the Insert Formula window - you
should basically see this: Value[myKey = field1]
\par - Modify this now to: Value[myKey = field1] * 10 (just to do some
mathematical function)
\par - Click OK 2 times to get back to your form
\par - Preview and test - you should be able to select any of the
items in the list and the result in the text box should change
appropriately
\par
\par Let me know if this works for you!!
\par
\par Scott L. Heim
\par Microsoft Developer Support
\par
\par This posting is provided "AS IS" with no warranties, and confers
no rights.
\par
\par }
 
S

Scott L. Heim [MSFT]

JR,

(** NOTE: You may want to read all of this before taking any action! <G>)

In that case, you can move the expression from the "Default Value" field
for the text box and use it as a "Rule" on your drop-down box:

- Right-click on your text box and choose Properties
- Click the "fx" button next to Value and "cut" the expression from the box
- Right-click on the drop-down box and choose Properties
- Click the Rules button
- Click Add
- Click Add Action
- From the Action box choose: Set a field's value
- Click the button next to Field, highlight your text box field and click OK
- Click the button next to Value and paste the expression you "cut" from
above
- Test!

In regard to the blank row, if you can use a default value from your XML
file then you can use these steps:

- Display the Data Source Task Pane
- Select Main from the Data Source drop-down
- Right-click on the node that represents your drop-down list and choose
Properties
- Set a default value (as an example, I used: 6-Item 1)

Now, the problem with using this option along with moving the expression to
a Rule is that the text box will not get populated with the value until
after a selection is made. So....after all of this <G> what I would do is
leave the expression as the "Default Value" for the text box and set one of
your options from the XML file as the default selection.

Now that I have totally confused you, let me know if this is a viable
option!

Scott L. Heim
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top