cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TheOpeningBat
Helper III
Helper III

disable button based on multiple user conditions in sharepoint list

Hello all,

 

I have a sharepoint list with userid, username, createddate columns.

User will fill have option to fill survey each day, if he tries to fill survey multiple times in a day, fill survey button should be disabled.

 

I tried below on OnSelect of fill survey button:

If(CountRows(Filter(UserReport, DateDiff(CreatedDate, Now(), Days)=0))>0, Notify("Survey already submitted", NotificationType.Error, 1000), Navigate(SurveyQuestions);

 

The above is working for date part, but not able to check for the user. It just disabled for all users based on todays date.

 

Any idea how it can be done. Many thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

@TheOpeningBat It's a little bit strange that it works only with Email and not with Author.Email, and I have my doubts that is works fine (it means that you have a column called Email in your sharepoint list).

About the delagation warning that you receive, this came from this part of the formula: 

 DateDiff(CreatedDate, Now(), Days)=0) because the DateDiff function is not delegable to Sharepoint.

To avoid it, you can use this kind of formula:

Created>Today() &&Created<=DateAdd(Today(),1,Days))

 

So, my final proposal 😊 for your formula is:

 If(CountRows(Filter(UserReport,  Created>=Today() && Created<DateAdd(Today(),1,Days) && Author.Email = currentUserEmail))>0,DisplayMode.Disabled, DisplayMode.Edit)

 

 

View solution in original post

13 REPLIES 13
JR-BejeweledOne
Super User
Super User

You need to add in a check for the user.   Are you already getting the user information using the Office365users connector?

 

If not, try setting a variable in the App start section:   Set(varUser, Office365Users.MyProfileV2().displayName

 

Then validate that against the created by in the list.   To disable the button you may want set a variable in the OnSelect based on your criteria and then use that variable in the Button DisplayMode property.

 

in your app start set your visibility variable to true:  Set(varSurveyButtonVisible, true)

 

In the submit button display mode property:  If(varSurveyButtonVisible,   DisplayMode.Edit, DisplayMode.Disabled)

When the variable is set to false based on your criteria in the onSelect, the button becomes disabled.



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.
gabibalaban
Super User II
Super User II

Hi @TheOpeningBat ,

 

You can filter UserReport list also on user who created the record: (before create a context or global variable to avoid delegation warning to keep the User().Mail - UpdateContext({currentUserEmail:User().Email})

 

 If(CountRows(Filter(UserReport, DateDiff(CreatedDate, Now(), Days)=0 && Author.Email = currentUserEmail ))>0, Notify("Survey already submitted", NotificationType.Error, 1000), Navigate(SurveyQuestions);

 

Isn't much easier if you prevent this by disabling the button if the user already take the survey on the current day. I mean to set DisplayMode property of the button to:

 If(CountRows(Filter(UserReport, DateDiff(CreatedDate, Now(), Days)=0 && Author.Email = currentUserEmail ))>0,DisplayMode.Disabled, DisplayMode.Edit)

 

Is a bad user experience to receive a NotificationError (no matter what!), so I think it better to avoid this.

 

Hope it helps ! 

Hi @gabibalaban ,

 

I tried the below on the DisplayMode Property of button but it says function countrows has some invalid arguments.

 

 If(CountRows(Filter(UserReport, DateDiff(CreatedDate, Now(), Days)=0) && UserReport.Email = currentUserEmail)>0,DisplayMode.Disabled, DisplayMode.Edit)

Could you tell if I am missing something?

@TheOpeningBat 

Please use Author instead of UserReport, as I wrote it in my formula.

@gabibalaban Still it’s giving the same error. 
sorry I’m not aware about Author. Actually I need to check from the Sharepoint list whether user has taken the survey

I look on your formula again and don't seems to look like mine... please put the paranthesis on the same place 

Hi @gabibalaban ,

Sorry my bad, on mobile might be I was not able to see properly. Was able to find the missing parenthesis on desktop.

 

However even if the user has taken the survey today, survey button is not disabled.

 

Also on the take survey button - where should i add Navigate(SurveyQuesitons)? OnSelect of the button or else where?

Hi @gabibalaban . If I don't use Author.Email & just use Email then it is working fine. Is that the correct way?

 

If that is fine then I can mark your answer as solution. Please let me know.

@TheOpeningBat It's a little bit strange that it works only with Email and not with Author.Email, and I have my doubts that is works fine (it means that you have a column called Email in your sharepoint list).

About the delagation warning that you receive, this came from this part of the formula: 

 DateDiff(CreatedDate, Now(), Days)=0) because the DateDiff function is not delegable to Sharepoint.

To avoid it, you can use this kind of formula:

Created>Today() &&Created<=DateAdd(Today(),1,Days))

 

So, my final proposal 😊 for your formula is:

 If(CountRows(Filter(UserReport,  Created>=Today() && Created<DateAdd(Today(),1,Days) && Author.Email = currentUserEmail))>0,DisplayMode.Disabled, DisplayMode.Edit)

 

 

View solution in original post

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,082)