Pergunta

I'm trying to develop a calculator type from in InfoPath where the user will be asked to end weight,height, and age. I will then take those values and use them to look up other values that are based on that number. For example if the column headers are Gender, Age, Height, L, M, and S. I want to find the 'L,M,S' values associated with that height. All values in the case are different. So if height were 45, L=-1, M=1, S=2; if height were 50, L= -2, M= 5, S=3.

In excel you a Vlookup with the syntax of :

Dim A as double
Dim Height as double
height = txtHeight.Value
A = Application.WorksheetFunction.VLookup(height, Range("C2:F652"), 2, False)

This would give you the "L" value for the row in which that height is located.

How can I do this in InfoPath? I have seen that are cascading queries you can do for dropdowns and comboboxes, but I want them to be able to type in a value, find a value on a SharePoint list based on that number and then return that number to another text box to use for my calculation.

Foi útil?

Solução

If the values you want to look up are in a SharePoint list, then you need to create a data connection to that list. Make sure to include all the fields you need. Don't load the data connection at form load.

Let the user enter the height. Create a rule for the height field that fires when the field changes. Add an action that sets the query field for the secondary data source to the value of the height field, then query the data connection. Now the secondary data source contains the record with that height and the fields in the secondary data source contain the values. You can copy the values into text boxes on the canvas.

More details: After you have set up a data connection to the Heights list, click the Heights field and add a rule by clicking New > Action.

enter image description here

Click the Add button and add an action to set a field's value.

enter image description here

Click the button next to the "Field" text box. If you don't see the top drop-down to select a different data source than the main data source, click the "Show Advanced View" link. Select the secondary data source for the Heights list, open the node for queryFields and the node below that and select the Height field.

enter image description here

Click the fx button next to the "Value" text box, then click "Insert Field or Group" and select the "height" field of the main data source.

enter image description here

OK out of all dialogs.

Add another rule to query for data.

enter image description here

Select the secondary data source to the Heights list.

Add another rule to set a field's value. For "Field" select the main data source field into which you want to copy the looked up value. For "Value" select the secondary data source and drill into the dataFields node until you see the field names. Select the desired field and OK out of all dialogs.

enter image description here

The rules panel should now look similar to this, but with your column names.

enter image description here

Test the form. Enter a valid height into the height field and click out of the field. The corresponding value from the height list will be written into the textbox. The screenshot shows the SharePoint list in the background with the item for heigt "66" highlighted. The value returned to the InfoPath text box "getV1" is from the "V1" field of the SharePoint list.

enter image description here

Hope that makes it clearer.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top