cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kenjoy84
Helper II
Helper II

If function in Forall

I want to set the mail address using a person's name from the data source.

However, there are some irregular data in data source("","NA"), on top of the user name.

So in such a case, I just want to skip and just want to search the actual user name.

However, when I use "If" function in Forall, I supposed that Forall just skip false case of if condition, but it seems to return something(maybe false or blank), so my below formula doesn't work well.

How to configure just skip the case of false in If function in ForAll?

Thank you for your support.

 

ForAll(Recipients, If(Not(psn in ["","NA"]),{
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
DisplayName:First(Office365Users.SearchUser({searchTerm:psn}).DisplayName).DisplayName,
Claims:"i:0#.f|membership|" & Lower(First(Office365Users.SearchUser({searchTerm:psn}).Mail).Mail),
Department:"",
Email:First(Office365Users.SearchUser({searchTerm:psn}).Mail).Mail,
JobTitle:"",
Picture:""
}))

1 ACCEPTED SOLUTION

Accepted Solutions

@Kenjoy84 

My apology...I didn't notice that I had the formula a little off.

Should be this:

ForAll(Filter(Recipients, !IsBlank(psn) || psn = "NA"),
   With({usr: First(Office365Users.SearchUser({searchTerm:psn}))},
       {
           '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
           DisplayName:usr.DisplayName,
           Claims:"i:0#.f|membership|" & Lower(usr.Mail),
           Department:"",
           Email:usr.Mail,
           JobTitle:"",
           Picture:""
       )
    )
)

 

This will return a table of records with the user information filtered by the criteria you need.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User III
Super User III

@Kenjoy84 

Consider filtering out the things you don't want in your ForAll and then only operating on the ones you do.  

This formula should give you what you need:

ForAll(Filter(Recipients, !IsBlank(psn) || psn = "NA"),
   {
       '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
       With({usr: First(Office365Users.SearchUser({searchTerm:psn}))},
           DisplayName:usr.DisplayName,
           Claims:"i:0#.f|membership|" & Lower(usr.Mail),
           Department:"",
           Email:usr.Mail,
           JobTitle:"",
           Picture:""
       )
   }

)

Also, consolidated the SearchUser to one time for this rather than multiple calls to the function.

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes Thank you!

The filter part works perfectly! 

However, additional your point about using "With" to consolidate function, it seems error and I can't solve, eventually.

Could you find out the solution for this? Thank you very much.

 

pic.jpg

@Kenjoy84 

My apology...I didn't notice that I had the formula a little off.

Should be this:

ForAll(Filter(Recipients, !IsBlank(psn) || psn = "NA"),
   With({usr: First(Office365Users.SearchUser({searchTerm:psn}))},
       {
           '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
           DisplayName:usr.DisplayName,
           Claims:"i:0#.f|membership|" & Lower(usr.Mail),
           Department:"",
           Email:usr.Mail,
           JobTitle:"",
           Picture:""
       )
    )
)

 

This will return a table of records with the user information filtered by the criteria you need.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

@RandyHayes Thank you, Randy! This works as I expected. I appreciate your clarification.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,464)