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 controldrpColumns
. 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 controltxtSearch
. This clears any text the user might have entered in the search box. -
Updating Context Variable:-
UpdateContext({locFiltered: false});
: Updates a context variable namedlocFiltered
and sets its value tofalse
. 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 thelocReferralList
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 usingDateAdd(Now(), -n)
, wheren
is the number of days ago.
- DateAdd and Now Functions:
DateAdd(Now(), -n)
: This function calculates a date that isn
days before the current date (Now()
). It is used here to set theLastUpdated
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
Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!