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 theIf
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.
- If the flow does not run successfully, the second block is executed:
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.
Happy #low-code learning
Dr. Amit Puri, Advisor and Consultant, Strengthening Digital Experiences, Modernize Cloud Journey with AI-Driven Transformation!