cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Oskarkuus
Level: Powered On

Permission how to control control visibility based on datasource?

I have a sharepoint list with five columns.

Name, Email, IsAdmin, IsCreator, IsReader

Name = first name and last name of regisrated user

Email = users email adress

IsAdmin = true/false if the user is an admin

IsCreator = true/false if the user is an creator

IsReader = true/false if the user is an reader (normal user)

 

How can i use this datasource (sharepoint list) and hide/show controls based on the true/false values

IF CURRENT USERS EMAIL EXIST IN DATASOURCE AND HAVE ISADMIN TO TRUE THEN SHOW XXX CONTROL

ELSE IF ISADMIN IS FALSE THEN HIDE CONTROL

 

How can i do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Oskarkuus
Level: Powered On

Re: Permission how to control control visibility based on datasource?

Thank you.

I think i found a solution that seems to work so far.

When app starts in the OnStart function i have this:

ClearCollect(collAppUsers;Admin_List);;Set(IsEkeTr;LookUp(collAppUsers;EpostAdress=User().Email;EkebyTräk));;
ClearCollect(collAppUsers;Admin_List);;Set(IsSten;LookUp(collAppUsers;EpostAdress=User().Email;Stenhamra));;
ClearCollect(collAppUsers;Admin_List);;Set(IsAdmin;LookUp(collAppUsers;EpostAdress=User().Email;SuperAdmin))

(yes changed the names on my variables)

 

 

Then on a button i have on the DisplayMode function:

If(IsEkeTr;DisplayMode.Edit;DisplayMode.Disabled)

Afaik this works. The lookup looks up the EmailAdress column in my sharepointlist (Admin_List) and compares it to current user of the app and then takes the value from the column (superadmin, stenhamra or ekebyträk). This seems to give the current user the right permission to use or not use the button.

 

So if the user have true value in the columns EkebyTräk, Stenhamra or SuperAdmin it will make the button Edit else Disabled (ofc using the correct variable (IsEkeTr, IsSten or IsAdmin)

 

3 REPLIES 3
RezaDorrani
Level 10

Re: Permission how to control control visibility based on datasource?

Hi @Oskarkuus 

 

Set Visible property of control to

 

CountRows(
Filter(
SharePointList,
Email.Email = User().Email && IsAdmin = 1
)
) > 0

 

 

However, please be aware of a bug with Yes/No field in SharePoint and PowerApps

I would recommend using Text field in SharePoint to set Yes/No

 

https://rezadorrani.com/index.php/2019/04/14/powerapps-filter-sharepoint-yes-no-column-bug/

 

Regards,

Reza Dorrani

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

K-A-R-L
Level 10

Re: Permission how to control control visibility based on datasource?

Hi @Oskarkuus ,

Have you tried the solution above?

As a workaround you could also try setting user profile on as a global variable on the AppStart() property of the app.

 Set(MyProfile,Office365Users.MyProfile()); //or you can also use User().Email

On the controls you want to hide/show based on the tue/false values set Visible() property to:

If(MyProfile.Mail in AdminList.Value,true,false) //AdminList is your SP Data Source, AdminList.Value is the Email column.

Best of luck

----------------------------------------------------------------------------
Thanks,
K-A-R-L


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If you thought this post was helpful, please give it a Thumbs Up.

 

Oskarkuus
Level: Powered On

Re: Permission how to control control visibility based on datasource?

Thank you.

I think i found a solution that seems to work so far.

When app starts in the OnStart function i have this:

ClearCollect(collAppUsers;Admin_List);;Set(IsEkeTr;LookUp(collAppUsers;EpostAdress=User().Email;EkebyTräk));;
ClearCollect(collAppUsers;Admin_List);;Set(IsSten;LookUp(collAppUsers;EpostAdress=User().Email;Stenhamra));;
ClearCollect(collAppUsers;Admin_List);;Set(IsAdmin;LookUp(collAppUsers;EpostAdress=User().Email;SuperAdmin))

(yes changed the names on my variables)

 

 

Then on a button i have on the DisplayMode function:

If(IsEkeTr;DisplayMode.Edit;DisplayMode.Disabled)

Afaik this works. The lookup looks up the EmailAdress column in my sharepointlist (Admin_List) and compares it to current user of the app and then takes the value from the column (superadmin, stenhamra or ekebyträk). This seems to give the current user the right permission to use or not use the button.

 

So if the user have true value in the columns EkebyTräk, Stenhamra or SuperAdmin it will make the button Edit else Disabled (ofc using the correct variable (IsEkeTr, IsSten or IsAdmin)

 

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 239 members 4,943 guests
Please welcome our newest community members: