Code Snippet #8
For Search
This code snippet demonstrates a dynamic approach to managing and displaying a list of referrals based on user input. It’s designed to update a collection named locReferralList
based on whether there’s text in a search input control (txtSearch
).
If(
!IsBlank(txtSearch.Text),
ClearCollect(
locReferralList,
Search(
locReferralList,
txtSearch.Text,
"FriendName",
"FriendEmail",
"ReferralNotes"
)
),
ClearCollect(
locReferralList,
{
FriendName: "Steve",
FriendEmail: "Steve@gmail.com",
ReferralNotes: "The application submitted. The application is under review.",
StateTip: "The application submitted",
State: Icon.LogJournal,
LastUpdated: DateAdd(
Now(),
-1
)
},
{
FriendName: "Vijay",
FriendEmail: "Vijay@outlook.com",
ReferralNotes: "The referral bonus unlocked! You will receive instructions for claiming the payout.",
StateTip: "The referral bonus unlocked!",
State: Icon.Unlock,
LastUpdated: Now()
},
{
FriendName: "Priyanka",
FriendEmail: "Priyanka@gmail.com",
ReferralNotes: "The referral bonus settled. The payout amount is credited in your account XX162",
StateTip: "The referral bonus settled.",
State: Icon.Money,
LastUpdated: DateAdd(
Now(),
-5
)
},
{
FriendName: "Farida",
FriendEmail: "Farida@gmail.com",
ReferralNotes: "The applicant needs support from the admission team. Help needed on the admission documentation.",
StateTip: "Admission Team Support Needed.",
State: Icon.Support,
LastUpdated: DateAdd(
Now(),
-4
)
},
{
FriendName: "John",
FriendEmail: "John@gmail.com",
ReferralNotes: "The applicant needs support from the admission team. Help needed on the admission documentation.",
StateTip: "Admission Team Support Needed.",
State: Icon.Unlock,
LastUpdated: DateAdd(
Now(),
-9
)
},
{
FriendName: "Sundar",
FriendEmail: "Sundar@gmail.com",
ReferralNotes: "The referral bonus settled. The payout amount is credited in your account XX162",
StateTip: "The referral bonus settled.",
State: Icon.Money,
LastUpdated: DateAdd(
Now(),
-10
)
},
{
FriendName: "Allen",
FriendEmail: "Allen@gmail.com",
ReferralNotes: "The applicant needs support from the admission team. Help needed on the admission documentation.",
StateTip: "Admission Team Support Needed.",
State: Icon.LogJournal,
LastUpdated: DateAdd(
Now(),
-7
)
}
)
);
Explanation
-
Conditional Logic with
If
:- TheIf
statement checks whether the text input controltxtSearch
is not blank. IftxtSearch
is not blank, it implies the user has entered a search query. - Handling the Search Query:- When the search query is present:
ClearCollect(locReferralList, Search(locReferralList, txtSearch.Text, "FriendName", "FriendEmail", "ReferralNotes"))
: This line clears thelocReferralList
collection and then populates it with items that match the search query. TheSearch
function looks for the query text in theFriendName
,FriendEmail
, andReferralNotes
fields of thelocReferralList
collection.
- Default Collection Data:- When the search box is blank:
- The second
ClearCollect
function is executed, which resets thelocReferralList
collection with a predefined set of records. Each record includes fields such asFriendName
,FriendEmail
,ReferralNotes
,StateTip
,State
, andLastUpdated
.
- The second
- Use of DateAdd and Now:- This
DateAdd(Now(), -n)
function is used to calculate dates relative to the current date (Now()
). For instance,DateAdd(Now(), -1)
sets theLastUpdated
field to one day before the current date.
In summary, this code snippet allows to dynamically filter a collection of referral records based on user input in a search field. If the user enters a search term, the collection is filtered to show only matching records. If the search box is empty, the collection is reset to a default set of records. This functionality enhances user interaction, enabling efficient searching and browsing through the referral data.
Happy #low-code learning
Dr. Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!