Get filtered values from SharePoint list column in InfoPath text field

Get filtered values from SharePoint list column in InfoPath text field

So here’s the situation: I needed to get all the values from a certain SharePoint list column in an InfoPath text field, so my talented colleague Derege Ardani sent me a link to this helpful article by John Liu.


But I needed my values filtered after a selection is made in a different field in my InfoPath form, so I’ve tried adding my filter in different ways that didn’t work, but eventually it did work and here’s the final syntax i used:

{code type=xpath}eval(eval(SharePointListItem_RW[DrugName = Medicine], ‘concat(d:Technology, “;”)’), “..”) {/code}

So how do we use this “scary” expression?

1. Create a data connection to your relevant SharePoint list.

2. Open the properties of your InfoPath text field and paste this syntax –

{code type=xpath}eval(eval(A, ‘concat(B, “;”)’), “..”) {/code}

insert xpath basic formula

insert xpath basic formula

 

3.  You need to replace “A” with your SharePoint list data connection data fields folder – so press the ‘Insert Field or Group’ button and choose your list data connection in the top drop down and then click the folder ‘d: SharePointListItem_RW’ once to mark it, afterwards press on the ‘Filter Data’ button.

d: SharePointListItem_RW with filter

click the folder ‘d: SharePointListItem_RW’ once to mark it, afterwards press on the ‘Filter Data’ button.

4. Add a filter rule based on one of your list’s columns compared to one of your InfoPath fields, after you add this filter your formula should like this:

Filter rule xpath

Filter rule xpath

 

5. Now you need to replace “B” with the SharePoint list column which it’s values you need to get, so press insert field or group choose your list data connection and choose the column you need from your SharePoint list data connection data fields.

6. Your xpath formula should now look like this:

xpath formula stage before last

xpath formula stage before last

7. Now the most important, tricky part is to delete the text before your column name ‘d:YourFieldname’.

8. So now your final xpath formula will look like this:final xpath formula

9. That’s it, hope this helps!