The Best Way to Replace Current User Email With Anonymous Email in Power Apps

I built an employee survey satisfaction application in Power Apps a few days ago. This application allows anonymous surveys from employees; here, I was required to convert the current user’s email address to an anonymous email.

So, in this article, I will explain how to replace current user email with anonymous email in Power Apps with a simple scenario.

Replace Current User Email With Anonymous Email in Power Apps

Look at the example below in the employee survey app.

When I toggle on the Is Anonymous Employee in the survey form, the characters before @ from the email in the email field are converted to stars. Again, when I toggled off, it displayed the current user’s email. Clicking the save button in the SharePoint list saves the current user’s email only, even if the displayed email is anonymous.

create anonymous email address from current user email in power apps

Follow the steps below to achieve this!

1. Add the code below on the OnStart property of the App object to convert the current user email into anonymous.

Set(AnonymousEmail,Concat(ForAll(Sequence(Find("@",User().Email)-1),"*"),Value)&Mid(User().Email,Find("@",User().Email)));

Here,

  • User().Email = Returns current user email address.
  • Find() function = Returns the index position of @ in the current user email address.
  • Sequence () function = Generates a series of numbers in a single-column table. [The formula subtracts one from the find() function output.]
  • Example: Email =PattiF@szg52.onmicrosoft.com
    • Find() = Returns 7 [@ position].
    • Sequence(7-1)= 6. It generates values from 1 to 6 in the table. like 1,2,3,4,5,6.
  • ForAll() function = Converts each number in the table into * star. Which means the table contains six stars.
  • Concat() function = It takes each star from the table and converts it into a single text. like ‘******’
  • Now, we converted the characters before @ in the email to stars. Let’s see how to combine this star text with the remaining.
  • Mid() function = Extracts the text from the given position in the main text. Here, within this function, find() returns @ position in the mail.
  • Example,
    • Email =PattiF@szg52.onmicrosoft.com
    • Find = 7
    • Mid() = @szg52.onmicrosoft.com
    • & operator concatenates the Concat() output and Mid() output. ******@szg52.onmicrosoft.com
  • So, the final email is stored in the AnonymousEmail variable.
power apps convert email to anonymous email

2. Then, provide the below code to the Default property of the email text field.

If(tgl_IsAnonymousEmployee.Value, AnonymousEmail, User().Email)

When the toggle value is true, it displays the anonymous email; if not, it shows the current user email.

tgl_IsAnonymousEmployee is the toggle control name.

convert current user email to anonymous email powerapps

3. While saving the form details, if you want to store the current user email, even if it is an anonymous survey, add the code below to the Update property of the email datacard in the form.

User().Email
create anonymous email in power apps from current user email

4. To submit the form details, provide the below code on the submit button.

SubmitForm(Frm_EmpSurvey)

Frm_EmpSurvey is the form name, and the SubmitForm() function submits the Power Apps form data to the SharePoint list.

how to create anonymous email address from current user email in power apps

Now, save and publish the app before previewing the Run the OnStart property of the App object.

power apps anonymous email

I hope you understand how to convert the characters in the email into stars and make it anonymous. This approach will be helpful when you must make the emails into anonymous emails.

Also, you may like:

>
Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial

FREE Power Platform Tutorial PDF

Download 120 Page FREE PDF on Microsoft Power Platform Tutorial. Learn Now…