I have a canvas app with an edit form, with several cards and combo boxes linked to SP person columns. Users may search by Email or DisplayName, but I have received feedback from users expressing annoyance at having to know an employee's middle initial when searching by DisplayName. I am attempting to configure a combo box's Items so the user may bypass middle initials if searching by name, but I have encountered some problems. Here is my Items code snippet:
Filter(
Office365Users.SearchUserV2(
{
searchTerm: Trim(Self.SearchText),
isSearchTermRequired: true
}
).value,
And(
If(
Not(IsBlank(Self.SearchText)),
StartsWith(
GivenName,
Trim(
Left(
Self.SearchText,
Find(
" ",
Self.SearchText
)
)
)
)
),
If(
" " in Self.SearchText,
Substitute(
Self.SearchText,
$"{Trim(
First(
Split(
Self.SearchText,
" "
)
).Value
)} ",
""
) in Surname,
true
),
AccountEnabled = true
)
)
The first If condition appears to be working correctly, as all GivenName matches are returned, but for the second condition, not all "GivenName Surname" matches are returned. The condition checks for a single space in SearchText, and if found, removes all text before and including it via Substitute(), and if not, returns true to ensure that GivenName matches are returned. Another condition specified for Surname is as follows:
If(
" " in Self.SearchText,
StartsWith(
Surname,
Substitute(
Self.SearchText,
$"{Trim(
First(
Split(
Self.SearchText,
" "
)
).Value
)} ",
""
)
),
true
)
This case results in the same outcome as with the previous case.
Is there another way I could rewrite the second If() statement to ensure all Surname matches are returned, or is there a mistake or delegation issue I am unaware of? I'd appreciate any advice, and thank you in advance!