views:

766

answers:

2

I am trying to build an Infopath form which populates fields with data back from a Sharepoint list. I set up a drop-down list box who's values get populated from a Sharepoint data source. That part works fine. Now I want other string fields to get automatically populated once the user selects one of the items from the list.
So I set up a rule to do this. I wrote an XPath formula to grab the attribute from the Sharepoint list

xdXDocument:GetDOM("Base Printers")
/dfs:myFields/dfs:dataFields/dfs:Base_Printers/@PNP_String

The problem is that this always grabs the attribute (PNP_String) from the first item in the list. I want to populate it with the proper printer (Base_Printers) based on the user's selection. So I have to index into Base_Printers, and then pick the PNP_String. So I tried this

.../dfs:Base_Printers[2]/@PNP_String

It will index into the 2nd item and return that PNP string, which is great!
But I need to index to the element the user picked, so I tried this:

.../dfs:Base_Printers[@Printer=my:basePrinter]/@PNP_String

Where @Printer is the attribute in the sharepoint list, and my:basePrinter is the local infopath variable of the Drop down list. And that does nothing for me. When I tried a literal value:

.../dfs:Base_Printers[@Printer='XYZ']/@PNP_String

It picked the right pnp string.
So my question is, how can I index into that array of printers based on the user's selection?

Thanks

A: 

By default XPath does not inherit context (e.g. local infopath variables) from the surrounding environment.

In XSLT it is up to the processor to provide a mechanism to allow you to populate global (i.e. defined in the root node) xsl:variable declarations which are then available in XPath as $name.

Since I don't know InfoPath I can't be more specific, but it should be documented (even if only indirectly via examples)...

Also note that you can use, in predicates (inside the []), full location paths with their own predicates, so if the selected value is available in the same document you can use that, something like

.../dfs:base_printers[@printer=/theform/theCombo/Values[@selected=true]]
Richard
+1  A: 

I think I figured it out.

xdXDocument:GetDOM("Base Printers")/dfs:myFields/dfs:dataFields
/dfs:Base_Printers[@Printer = current()]/@PNP_String

For some strange reason, it works when you use:

@Printer = current()

But not when you use:

@Printer = my:basePrinter

Even though both current() and my:basePrinter return the same string.

Weirdness...

OTisler
I think what's going on is:Attribute != Node, but Attribute.string == string
Jweede
That's what I thought, but I used the string() function to convert, and it still wasn't working!
OTisler