For  sending mail for referral

Chapter - 06

Visit to buy the book on Citizen Development https://go.amitpuri.com/buynow

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.

Happy #low-code learning

Visit: www.amitpuri.com

Id: Chapter-06-CS00003

Category: Chapter 06

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

Code Snippet # 2
Chapter-06-CS00002 - Code Snippet # 2
Code Snippet # 2
Chapter-08-CS00002 - Code Snippet # 2
Code Snippet # 1
Chapter-06-CS00001 - Code Snippet # 1