Get Email from SharePoint List Person Field
Filtering SharePoint records by email is a routine task for many app builders. The goal is often to reflect the data related to the current user. But how do you do this without stumbling into the pitfalls of non-delegable queries? Dive in to uncover the mystery.
A Glimpse at Filtering SharePoint Records by Email
SharePoint’s capability to filter records by an email address is a topic that garners ample attention. The objective? Achieve this in a delegable manner. Let’s delve deeper.
The Challenges of Filtering by Current User
Among the plethora of questions that arise, the chief one is about filtering a SharePoint list to mirror the records of the present user. Get it right, and the rest is smooth sailing.
Common Mistakes
Consider a SharePoint list tracking property details. To showcase only those records entered by the active user, one might be tempted to utilize a gallery control with a filter condition resembling:
Filter(PropertiesList, 'CreatedBy'.Email = User().Email)
This logic, although seemingly correct, is flawed. It’s flagged as non-delegable and won’t display all the records as anticipated.
Why This Approach Fails
Delegable queries are those Power Apps can relay to the data source for execution outside its environment. But here’s the crux: SharePoint, being an external data source, is oblivious to the current Power Apps user. Hence, it can’t run a query that references the Power Apps User entity.
Solutions to the Conundrum
Although direct reference to the User object isn’t feasible, there’s a way around it. The key is expressing the user’s email address statically, thus bypassing the need for data source resolution.
Method 1: Harnessing Variables
First, park the email address in a variable, then call upon that variable during the filter function. Here’s the syntax to define a variable:
Set(emailVariable, User().Email)
Now, deploy this variable within the Filter function. This revised formula is delegable:
Filter(PropertiesList, 'CreatedBy'.Email = emailVariable)
Method 2: The Power of the With Command
The With function comes to the rescue, evaluating and storing the result of User().Email in a variable named userEmail. This static value can then be utilized in the Filter function, ensuring a delegable SharePoint query:
With({userEmail: User().Email}, Filter(PropertiesList, 'CreatedBy'.Email = userEmail))
Wrapping Up
To adeptly filter SharePoint columns in a delegable manner, rely on a static value either through a variable or the With function. This strategy is versatile, extending beyond the Filter function to others like the LookUp function. Remember, with the right technique, you can unlock seamless SharePoint filtering.
If you’re grappling with any of the steps or need deeper insights into SharePoint or any tech-related issue, don’t hesitate to contact us. We’re here to help, guide, and ensure you have all the tools for success.