For  Search

Chapter - 06

Visit to buy the book on Citizen Development https://go.citizendeveloper.codes/buynow

Code Snippet #8

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:- The If statement checks whether the text input control txtSearch is not blank. If txtSearch 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 the locReferralList collection and then populates it with items that match the search query. The Search function looks for the query text in the FriendName, FriendEmail, and ReferralNotes fields of the locReferralList collection.
  • Default Collection Data:- When the search box is blank:
    • The second ClearCollect function is executed, which resets the locReferralList collection with a predefined set of records. Each record includes fields such as FriendName, FriendEmail, ReferralNotes, StateTip, State, and LastUpdated.
  • 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 the LastUpdated 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

Visit: www.citizendeveloper.codes

Id: Chapter-06-CS00008

Category: Chapter 06

Dr. Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!

Code Snippet # 10
Chapter-08-CS00010 - Code Snippet # 10
Code Snippet # 1
Chapter-08-CS00001 - Code Snippet # 1
Code Snippet # 6
Chapter-06-CS00006 - Code Snippet # 6