Citizendeveloper.codes!

Hands-on-labs:Power Fx Solutions for Referral Management use case of Jane Doe

Code snippets collection in Power Fx Chapter in the book

author image
Amit Puri

Advisor and Consultant

Posted on 08 Feb 24

This chapter delves into a curated collection of Power Fx code snippets designed to streamline referral management tasks within Power Apps. From generating unique referral codes and validating email inputs to intricate operations like sorting, filtering, and dynamically updating lists based on user interactions, these snippets cover a broad spectrum of functionalities.

Each piece of code is meticulously explained to aid developers in understanding and applying these solutions effectively. Whether it’s enabling controls based on specific criteria, sending emails through Power Automate, or managing the display of referral lists with custom sort and search functionalities, this chapter serves as a comprehensive guide.

It not only demonstrates the versatility and power of Power Fx but also equips developers with the tools to enhance user experience and operational efficiency in their applications.

Code Snippet #1

For referral code generation in Power Fx

   Concat(
        FirstN(
            Shuffle(
                Split(
                    "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789",
                    ""
                )
            ),
            8
        ),
        Result
    )

Explanation

  • Split("abcdefghijklmnopqrstuvwxyz...6789", ""): - This function splits the provided string into an array of individual characters. The string is a long sequence of the alphabet followed by numbers 0 to 9, repeated several times. The split delimiter is an empty string "", so each character in the string becomes a separate item in the resulting array.

  • Shuffle(...): - This function takes the array created by Split and randomizes the order of its elements. After this, the array’s elements (individual characters) are in a random order.

  • FirstN(..., 8): - This function takes the first 8 elements from the shuffled array. Since the array was randomized by Shuffle, these 8 characters are randomly selected each time the formula is run.

  • Concat(..., Result): - The Concat function is used to concatenate (join together) the elements of the array. Concat would take an array or table and a formula to apply to each record of that array/table. In this case, it is to join the 8 random characters into a single string. If Result is intended to be used.

So, the overall purpose of this formula to generate a random string of 8 characters, each character being a letter (a-z) or a digit (0-9) i.e referral code in this case.

Code Snippet #2

For validating and enabling required control on the screen

This Power Fx code is used within a Power Apps canvas app to control the display mode of a button based on the validation of an email address entered into a text input control (named txtFriendEmail).

   If(
        IsMatch(
            txtFriendEmail.Text,
            "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"
        ) && Last(
            Split(
                txtFriendEmail.Text,
                "@"
            )
        ).Result in [
            "gmail.com",
            "outlook.com"
        ],
        DisplayMode.Edit,
        DisplayMode.Disabled
    )

Explanation

  • IsMatch(txtFriendEmail.Text, "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$"): - this IsMatch function checks whether the text in txtFriendEmail matches the specified regular expression. The regular expression ^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$ is used to validate the format of an email address. It ensures the email:
    • Starts with alphanumeric characters, dots, underscores, or hyphens.
    • Contains an @ symbol.
    • Has a domain part with alphanumeric characters or hyphens followed by a period.
    • Ends with a top-level domain that is 2 to 4 characters long.
  • Last(Split(txtFriendEmail.Text, "@")).Result in ["gmail.com", "outlook.com"]: - this Split(txtFriendEmail.Text, "@") function splits the email address at the @ symbol. The Last(...) function gets the last part of the split result, which is the domain of the email address. This part checks if the domain is either gmail.com or outlook.com.

  • If(..., DisplayMode.Edit, DisplayMode.Disabled): - This is an If statement that sets the display mode based on the above conditions. If both conditions are true (the email is in the correct format and the domain is either gmail.com or outlook.com), the display mode is set to DisplayMode.Edit. If either of the conditions is false, the display mode is set to DisplayMode.Disabled, making the button disabled.

In summary, this code is used to enable or disable a button in a screen based on whether the email address entered in the txtFriendEmail text input is valid and belongs to either the gmail.com or outlook.com domains.

Code Snippet #3

For sending mail for referral

The provided Power Fx code snippet is used within a Power Apps application to interact with a Power Automate flow named ‘Send-a-email-to-friend-with-referral-code’. The code sends an email to a specified address and handles the response to indicate success or failure of the operation.

   If(
        'Send-a-email-to-friend-with-referral-code'.Run(
            txtFriendEmail.Text,
            "Referral Instructions",
            lblReferralCode.Text,
            User().FullName
        ),
        Notify(
            "Email sent to " & txtFriendEmail.Text,
            NotificationType.Success
        );
        Reset(txtFriendEmail);
        ,
        Notify(
            "Error, We are not able to send mail!",
            NotificationType.Error
        )
    );

Explanation

  • Calling the Power Automate Flow named 'Send-a-email-to-friend-with-referral-code'.Run(txtFriendEmail.Text, "Referral Instructions", lblReferralCode.Text, User().FullName): - This part calls the Power Automate flow 'Send-a-email-to-friend-with-referral-code'. The .Run(...) function executes the flow with the following parameters: - txtFriendEmail.Text: The email address entered into a text input control (presumably where the user inputs the friend’s email). - "Referral Instructions": A string literal, likely the subject or a part of the email content. - lblReferralCode.Text: The text of a label control, possibly containing a referral code to be sent in the email. - User().FullName: The full name of the current user, retrieved from the user’s profile in Power Apps.

  • Handling the Response from the Flow: This If(..., ..., ...); If statement that checks the result of the flow execution. If the flow runs successfully, the first block of code inside the If statement is executed: - Notify("Email sent to " & txtFriendEmail.Text, NotificationType.Success);: Displays a success notification message to the user, confirming that the email has been sent. - Reset(txtFriendEmail);: Resets the text input control where the friend’s email was entered, likely to clear it for future input.

    • If the flow does not run successfully, the second block is executed:
      • Notify("Error, We are not able to send mail!", NotificationType.Error): Displays an error notification message to the user, indicating that the email could not be sent.

In summary, this Power Fx code snippet is designed to integrate a Power Apps application with a Power Automate flow. The flow is responsible for sending an email with referral instructions and a referral code. The Power Apps application calls this flow, passes necessary parameters, and then provides feedback to the user based on whether the email sending operation was successful or not.

Code Snippet #4

For the sort dropdown

This code snippet uses the ClearCollect function to create a collection named locSortDropdown and populate it with a table of data.

   ClearCollect(
        locSortDropdown,
        Table(
            {
                DisplayColumn: "No sort", ColumnName: ""
            },
            {
                DisplayColumn: "State", ColumnName: "State"
            },
            {
                DisplayColumn: "Friend Name", ColumnName: "FriendName"
            },
            {
                DisplayColumn: "Last Updated", ColumnName: "LastUpdated"
            }
        )
    );

Explanation

  • ClearCollect Function: - ClearCollect(collectionName, items...): This function clears any existing data in the specified collection (collectionName) and then collects the items into it. In your code, locSortDropdown is the name of the collection being created or updated.

  • Table Function: - Table(...) is used to create a table with the specified records. Each record is defined within curly braces {}.

  • Records in the Table: - The table created in your code consists of four records, each with two properties: DisplayColumn and ColumnName.

    • { DisplayColumn: "No sort", ColumnName: "" }: The first record. DisplayColumn is a label that might be displayed in the UI, and ColumnName is an empty string, indicating no sorting.
    • { DisplayColumn: "State", ColumnName: "State" }: The second record. This indicates that items can be sorted by a column named “State”.
    • { DisplayColumn: "Friend Name", ColumnName: "FriendName" }: The third record for sorting by a “FriendName” column.
    • { DisplayColumn: "Last Updated", ColumnName: "LastUpdated" }: The fourth record for sorting by a “LastUpdated” column.

In summary, this code is creating a collection named locSortDropdown which is intended to be used for a sorting dropdown control in a Power Apps canvas screen. The collection contains options for sorting data by different columns (like “State”, “Friend Name”, and “Last Updated”), as well as an option for ‘No sort’. The DisplayColumn values are what will be shown to the user in the dropdown, while the ColumnName values probably correspond to the actual column names in the data source that the sorting will be applied to.

Code Snippet #5

Populating sample data in referral list

It uses the ClearCollect function to create or update a collection named locReferralList. This collection is populated with a series of sample records, each representing information about a referral.

    ClearCollect(
        locReferralList,
        {
            FriendName: "Steve",
            FriendEmail: "Steve@gmail.com",
            ReferralNotes: "The application submitted. The application is under review.",
            StateToolTip: "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.",
            StateToolTip: "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",
            StateToolTip: "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.",
            StateToolTip: "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.",
            StateToolTip: "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",
            StateToolTip: "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.",
            StateToolTip: "Admission Team Support Needed.",
            State: Icon.LogJournal,
            LastUpdated: DateAdd(
                Now(),
                -7
            )
        }
    );

Explanation

  • ClearCollect Function: - ClearCollect(collectionName, items...): This function clears any existing data in the specified collection (collectionName) and then collects the items into it. In your code, locReferralList is the name of the collection being created or updated.

  • Records in the Collection: - Each record in the collection is defined within curly braces {} and represents information about a referral. The fields in each record are:
    • FriendName: The name of the friend being referred.
    • FriendEmail: The email address of the friend.
    • ReferralNotes: Notes or comments about the referral’s status or other relevant information.
    • StateToolTip: A short tooltip description about the current state of the referral.
    • State: An icon from the Power Apps icon library (such as Icon.LogJournal, Icon.Unlock, Icon.Money, Icon.Support) representing the current status or category of the referral.
    • LastUpdated: The date and time when the referral was last updated. This is calculated using DateAdd(Now(), -n), where n is the number of days ago the record was last updated.
  • Usage of DateAdd and Now:
    • Now() returns the current date and time.
    • DateAdd(Now(), -n) subtracts n days from the current date, setting the LastUpdated field to a past date.

In summary, this code is creating or updating a collection named locReferralList with detailed records of different referrals. Each record includes information like the friend’s name and email, notes on the referral, a tooltip for quick information, an icon to visually represent the status, and the last updated date.

Code Snippet #6

For toggling sort on selected column (or sort field)

This code snippet performs a conditional operation that involves sorting a collection based on a selected column from a dropdown control and toggling the sort order.

    If(
        !IsBlank(drpColumns.Selected.ColumnName),
        UpdateContext({locSortOrder: !locSortOrder});
        ClearCollect(
            locReferralList,
            SortByColumns(
                locReferralList,
                drpColumns.Selected.ColumnName,
                If(
                    locSortOrder,
                    Ascending,
                    Descending
                )
            )
        );
    )

Explanation

  • Conditional Check Using IsBlank:-If(!IsBlank(drpColumns.Selected.ColumnName), ...): This If statement checks if the ColumnName property of the selected item in the dropdown control drpColumns is not blank. It ensures that a column has been selected for sorting.

  • Toggling Sorting Order:- UpdateContext({locSortOrder: !locSortOrder});: If a column is selected, this line toggles the value of the context variable locSortOrder. If locSortOrder is currently true, it becomes false, and vice versa. This toggle changes the sort order between ascending and descending.

  • Sorting the Collection:- ClearCollect(locReferralList, SortByColumns(locReferralList, drpColumns.Selected.ColumnName, If(locSortOrder, Ascending, Descending))):

    • SortByColumns(locReferralList, drpColumns.Selected.ColumnName, If(locSortOrder, Ascending, Descending)): This function sorts the locReferralList collection by the column selected in the dropdown (drpColumns.Selected.ColumnName). The sort order is determined by the locSortOrder variable: ascending if locSortOrder is true, descending if false.
    • ClearCollect(...): This function first clears the locReferralList collection and then repopulates it with the sorted data. This ensures that the collection always reflects the current sort order and the selected column for sorting.

In summary, this code snippet is used for dynamically sorting a collection (locReferralList) based on a user’s selection from a dropdown control (drpColumns). It provides functionality to toggle the sorting order each time the sorting operation is triggered, allowing users to easily switch between ascending and descending sort orders. This kind of dynamic data manipulation is useful in scenarios where users need to interact with and organize large sets of data.

Code Snippet #7

Filter and updating a list of referrals

This code snippet demonstrates a combination of conditional logic, collection manipulation, and sorting. It’s designed to update and filter a collection named locReferralList based on certain conditions.

    UpdateContext({locFiltered: !locFiltered});
    If(
        locFiltered,
        ClearCollect(
            locReferralList,
            Filter(
                locReferralList,
                State in [
                    Icon.LogJournal,
                    Icon.Unlock
                ]
            )
        ),
        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
                )
            }
        )
    );
    If(
        !IsBlank(drpColumns.Selected.ColumnName),
        ClearCollect(
            locReferralList,
            SortByColumns(
                locReferralList,
                drpColumns.Selected.ColumnName,
                If(
                    locSortOrder,
                    Ascending,
                    Descending
                )
            )
        );
        
    );

Explanation

  • Toggle Filter State:- UpdateContext({locFiltered: !locFiltered});: This line toggles the value of a context variable named locFiltered. If locFiltered is true, it becomes false, and vice versa. This variable is used to track whether the list is filtered or not.

  • Conditional Collection Update:- The first If statement checks the state of locFiltered:
    • If locFiltered is true, it applies a filter to locReferralList and clears and re-collects it with only the items where the State is either Icon.LogJournal or Icon.Unlock.
    • If locFiltered is false, it clears and re-collects locReferralList with a predefined set of records, each containing details like FriendName, FriendEmail, ReferralNotes, StateTip, State, and LastUpdated.
  • Conditional Sorting of the Collection:- The second If statement checks if the selected item from a dropdown (drpColumns.Selected.ColumnName) is not blank. This dropdown allows the user to choose a column to sort by.
    • If a column is selected, it sorts locReferralList by the selected column. The direction of the sort (ascending or descending) is determined by the value of another context variable locSortOrder.
    • SortByColumns(locReferralList, drpColumns.Selected.ColumnName, If(locSortOrder, Ascending, Descending)): This function sorts locReferralList based on the selected column name and the sort order.

In summary, this code manages the data in the locReferralList collection based on user interactions. It allows toggling between a filtered and unfiltered state of the list, and it also provides functionality for sorting the list based on a user-selected column. The list can be filtered to show only certain types of referrals (based on the State field) and sorted by any column chosen by the user. This kind of dynamic data manipulation is common in Power Apps for creating interactive and responsive user interfaces.

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.

Code Snippet #9

For reseting screen

This code snippet performs a series of actions to reset certain controls and update a collection with predefined data. It’s likely part of a larger application where user interactions affect the display and sorting of referral data.

    Reset(drpColumns);
    Reset(txtSearch);
    UpdateContext({locFiltered: false});
    ClearCollect(
        locReferralList,
        {
            FriendName: "Steve",
            FriendEmail: "Steve@gmail.com",
            ReferralNotes: "The application submitted. The application is under review.",
            StateToolTip: "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.",
            StateToolTip: "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",
            StateToolTip: "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.",
            StateToolTip: "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.",
            StateToolTip: "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",
            StateToolTip: "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.",
            StateToolTip: "Admission Team Support Needed.",
            State: Icon.LogJournal,
            LastUpdated: DateAdd(
                Now(),
                -7
            )
        }
    );

Explanation

  • Resetting Controls:- Reset(drpColumns);: Resets the dropdown control drpColumns. This typically means that any selection made by the user in this dropdown will be cleared and set back to its default state. Reset(txtSearch);: Resets the text input control txtSearch. This clears any text the user might have entered in the search box.

  • Updating Context Variable:- UpdateContext({locFiltered: false});: Updates a context variable named locFiltered and sets its value to false. This variable is likely used elsewhere in the app to track whether certain filters are applied to the data.

  • Populating the Collection with Predefined Data:- This ClearCollect(locReferralList, {...}, {...}, ...); function clears any existing data in the locReferralList collection and then populates it with a new set of predefined records. Each record in this collection represents a referral and includes fields such as:
    • FriendName: The name of the referred friend.
    • FriendEmail: The email address of the referred friend.
    • ReferralNotes: Notes or comments about the referral.
    • StateToolTip: A tooltip text that likely provides additional information about the referral’s status.
    • State: An icon (from Power Apps’ icon library) representing the current status or category of the referral.
    • LastUpdated: The date and time when the referral was last updated, calculated using DateAdd(Now(), -n), where n is the number of days ago.
  • DateAdd and Now Functions:
    • DateAdd(Now(), -n): This function calculates a date that is n days before the current date (Now()). It is used here to set the LastUpdated field in the records.

In summary, this code snippet is part of a user interface in a canvas screen where users can search, filter, and sort a list of referrals. The code resets user selections in dropdown and search controls, clears any applied filters, and repopulates the locReferralList collection with a default set of referral records. This kind of functionality is useful for providing a “reset” or “clear filters” feature in the app.

Happy #low-code learning


If you are interested in Citizen Development, refer to this book outline here on A Guide to Citizen Development in Microsoft 365 with Power Platform, Now, available on, Select the Amazon marketplace based on your location to purchase and read the book on Kindle or on the web
Amazon Kindle India Amazon Kindle US Amazon Kindle UK Amazon Kindle Canada Amazon Kindle Australia

Also, you can look at this blog post series from various sources.

  • Hackernoon
  • Hashnode
  • Dev.to
  • Medium
  • Stay tuned! on Generative AI Blog Series

    We are advocating citizen development everywhere and empowering business users (budding citizen developers) to build their own solutions without software development experience, dogfooding cutting-edge technology, experimenting, crawling, falling, failing, restarting, learning, mastering, sharing, and becoming self-sufficient.
    Please feel free to Book Time @ topmate! with our experts to get help with your Citizen Development adoption.


    Share on

    Comments