In this guide, you’ll learn how to implement a label that dynamically changes based on the time of day and incorporates the user’s first name for a personalised touch
- The first part of the code is used to generate a greeting based on the current time. Here’s what it does:
Withfunction is used to create a temporary variable called
conHour, which is set to the current hour of the day using the
Now()function and the
Text()function to format it as a two-digit number.
Iffunction is then used to check the value of
conHourand generate a greeting based on the time of day:
- If the hour is between 0 (midnight) and 5am, the greeting will be “Good night, “
- If the hour is between 5am and 12pm, the greeting will be “Good morning, “
- If the hour is between 12pm and 6pm, the greeting will be “Good afternoon, “
- If the hour is between 6pm and midnight, the greeting will be “Good evening, “
- If none of the above conditions are met, no greeting will be displayed (an empty string).
&operator is used to concatenate the greeting with the result of the second part of the code.
- The second part of the code is used to extract the first name from the user’s full name. Here’s what it does:
Firstfunction is used to extract the first item from the result of the
ForAllfunction is used to loop through each word in the user’s full name (which is obtained using the
User().FullNamefunction) and create a new record with a field called
Resultthat contains the value of the current word.
Splitfunction is used to split the full name into an array of words based on the space character.
ThisRecordfunction is used to refer to the current record being created by the
.Valueproperty is used to get the value of the
Resultfield for the current record.
Overall, this code is used to generate a personalised greeting for the user based on the current time of day and their first name.