Saturday, June 6, 2009

InfoPath filters. Where's my 'Where' clause...

I have a copy of an old database in the form of an Excel dump. Ive uploaded the Excel file as a separate list in sharepoint.

GOAL:
Create an online Asset Inventory form in sharepoint that prepopulates field data from my sharepoint list. IE. When user enters an AssetTag that already exists in my sharepoint list, then prepopulate my form's serial#, model#, etc fields, with the values from the sharepoint list. Prepopulating these fields reduces likelihood of user error when completing machine details in my form.

PROBLEM:
I created a Rule on my myAssetTag field in my infopath form.
It says if myAssetTag = DataSourceAssetTag, then fire more rules:
a) set myModelNum to DataSourceModel,
b) set mySerialNum to DataSourceSerialNum, etc.
(Nested rules, all attached to my myAssetTag field.)

When I ran the form it did prepopulate information in the corresponding fields, but it picked the first row of data from the existing sharepoint list, not the data of the specific AssetTag that was entered by the user.

What I really wanted to say was:
myModelNum field should equal DataSourceModel where DataSrouceAssetTag equals myAssetTag.

SOLUTION:
Create a filter in InfoPath. I find this 'feature' somewhat awkward in InfoPath. One has to pay close attention to each window while completing this.

When creating the rule "myModelNum isequalto DataSourceModel", then selecting the Value of 'DataSourceModel', you have to first highlight the field name, THEN select FILTER. This filter button doesnt exist anywhere else, except, and only after a field is highlighted. Once I had the filter box open, I said: 'DataSourceAssetTag is equalto myAssetTag."

This filter is essentially the 'Where' clause I was trying to find. In infopath, the final rule looked like this:

Set a field's value
Field: myModelNum
Value: @DataSourceModel[@DataSourceAssetTag = myAssetTag]

Meaning: myModelNum = DataSourceModel where DataSourceAssetTag = myAssetTag.

Certainly not difficult, but it actually took me awhile to find the right filter, and to make sure I was in the correct window to even be offered the Filter option. Instead I often kept ending up in a New Rule window, which did not meet my needs.

I guess the lesson here was to tread lightly. Its easy to go through next/next/finish and then realize youve completely missed the key step in the process.

No comments:

Post a Comment