Help needed with some conditional logic


#1

Can anyone suggest a reason why the conditional logic for this search function is not working? In the attached, if you put “Jane” into Given name - all fine, if you put “Brown” into Last name - all fine, if you put both “Jane” and “Brown” in it falls over. I’ve used string logic with a && boolean thinking it would work to search both columns in the repeater but it doesn’t .
NewUIV0.11_Separatefields.rp (5.7 MB)


#2

Hi!

You can do this with a single filter and without any Else IFs. The filter itself can deal with the fields being blank or not.

Assuming v_givenName is a local variable containing the text of the given name field and v_lastName is the same for the last name field:

[[ (v_givenName != “” && v_lastName == “” && Item.GivenName == v_givenName) || (v_givenName == “” && v_lastName != “” && Item.LastName == v_lastName) || (v_givenName != “” && v_lastName != “” && Item.LastName == v_lastName && Item.GivenName == v_givenName) ]]

The thing to remember is that a filter evaluates as TRUE or FALSE for each row, showing the row only if it evaluates to true. Let’s break it down for each set of parentheses:

(v_givenName != "" && v_lastName == "" && Item.GivenName == v_givenName)

This says, "Show the row if v_givenName isn’t blank AND v_lastName is blank AND v_givenName matches value in the GivenName column.

(v_givenName == "" && v_lastName != "" && Item.LastName == v_lastName)

This says, "Show the row if v_givenName is blank AND v_lastName isn’t blank AND v_lastName matches value in the LastName column.

(v_givenName != "" && v_lastName != "" && Item.LastName == v_lastName && Item.GivenName == v_givenName)

This says, "Show the row if v_givenName isn’t blank AND v_lastName isn’t blank AND v_givenName matches the value in the GivenName column AND v_lastName matches value in the LastName column.

Only one of these can be true at a time. These or OR-ed together with double-pipes ("||") so if any of those things is true, it will be true for the row. Note that if both fields are blank, the filter will return no rows.

I updated your file. I also got rid of the FullName column, as it was inaccurate for some entries, and it’s easy enough just to concatenate given and last into a single text display.

NewUIV0.11_Separatefields.rp (5.7 MB)

[Edit] If you want to drastically speed up your prototype, do the following:

In the repeater Style tab, turn on pagination and set items per page to 1. This will cause the repeater to load almost immediately. (You’ll change this through code later to show more rows.)

Take that Set Filter command above out of the button and instead put into OnLoad (not OnItemLoad) of the repeater. Note that once a filter is set, it remains active, though you will need to force it to re-evaluate when something changes outside of the repeater (in this case, the text of the name fields).

In the button, put the following command where the Add Filter command used to be:

Set Items per page of (Repeater) to 20

You can make items-per-page unlimited if it’s important that all matching rows show, but it is a prototype after all, so limiting it will speed things up. Making it 10, for instance, will make it very responsive. Note that this command will cause the (still-active) filter to re-evaluate.

Here’s another version of your file with those changes:
NewUIV0.11_Separatefields_2.rp (5.8 MB)

[Edit] Forgot about the case-sensitivity that needs to be removed:

[[ (v_givenName != “” && v_lastName == “” && Item.GivenName.toLowerCase() == v_givenName.toLowerCase()) || (v_givenName == “” && v_lastName != “” && Item.LastName.toLowerCase() == v_lastName.toLowerCase()) || (v_givenName != “” && v_lastName != “” && Item.LastName.toLowerCase() == v_lastName.toLowerCase() && Item.GivenName.toLowerCase() == v_givenName.toLowerCase()) ]]


closed #3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.