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

Re: Limiting Data Visibility Based On User ID

@rebeccas @v-xida-msft 

I received a number of errors when inputting this.

 

I had to (unfortunately) create a new app based on a new table.

 

This is what I put for the "App" in the "OnStart" box:

Set(_CurrentUser, User())

 

Then in the BrowseGallery1 in "Items":

SortByColumns(Filter([@'Rep 1 Test'], StartsWith(Title, TextSearchBox1.Text)&& 'CreatedBy'.DisplayName=_User().FullName),"Title", If(SortDescending1, Descending, Ascending))

 

I got 5 errors for the BrowseScreen1

  1. Name isn't valid.
  2. Invalid use of "."
  3. Invocation of unknown or unsupported function
  4. Invalid use of "."
  5. Invalid argument type

 

bmurphy1
Level: Powered On

Re: Limiting Data Visibility Based On User ID

@rebeccas @v-xida-msft 

 

And when I do test the app, the info I input does populate the sharepoint list.  But it is not visible to me on the app.

Super User
Super User

Re: Limiting Data Visibility Based On User ID

It won't be _User().FullName ...it is either User().FullName or _CurrentUser on the filter and for the Set part, if that is what you are using it needs to be Set(_CurrentUser, User().FullName)

 

Instead of two options lets do:

 

App - OnStart = Set(_CurrentUser, User().FullName)

(after you put this in click on the three dots next to App and click the "Run OnStart" , this will make it set that variable). To double check it is set you click at the top View/Variables and it should be listed as a Global variable there.

 

For your Gallery Filter it should be _CurrentUser instead of the _User().FullName

 

If it where me I would change that to say:

 

SortByColumns(Search(Filter, 'CreatedBy'.DisplayName=_CurrentUser), TextSearchBox1.Text, "Title"),"Title",If(SortDescending1, Descending, Ascending))

 

If I know my data is good I don't concern myself with delegation warnings, I dislike StartsWith, but if they bother you then you can do a few extra steps and still have it work good with no warnings.

 

Create a collection on the screens load that filters for only the persons items and then you can put the collection in place of your data source name on your original items:

 

Screen with gallery - OnVisible= ClearCollect(CollMyItems, Filter('Rep 1 Test', 'Created By'.DisplayName=_CurrentUser))

 

Gallery Items = SortByColumns(Filter(CollMyItems, StartsWith("Title", TextSearchBox1.Text)),"Title", If(SortDescending1, Descending, Ascending))

 

 

 

 

Dual Super User
Dual Super User

Re: Limiting Data Visibility Based On User ID

The first thing I notice is that you are setting _CurrentUser as the variable, but then using _User().Fullname in your filter.  If the user is stored as _CurrentUser then it should read _CurrentUser.Fullname. I think that's actually the source of all 5 of your errors.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
Super User
Super User

Re: Limiting Data Visibility Based On User ID

Sorry..on that last post I noticed the Set I had is missing ()

 

Set(_CurrentUser, User().FullName)

 

See once you do that first part it is storing the current users name as a text field that can be referred to anywhere else in the app so from there you will be able to refer to it like it is just a text.

 

** I just went and fixed it, getting confusing**

bmurphy1
Level: Powered On

Re: Limiting Data Visibility Based On User ID

@rebeccas 

Ok that worked so far.  But then it broke the delete function.

 

OnSelect = Remove([@'Rep 1 Test'], BrowseGallery1.Selected); If (IsEmpty(Errors([@'Rep 1 Test'], BrowseGallery1.Selected)), Back())

Community Support Team
Community Support Team

Re: Limiting Data Visibility Based On User ID

HI @bmurphy1 ,

Could you please share a bit more about the issue with your Remove formula?

Do you mean that the IsEmpty(Errors(...)) could not work when you remove an record from your Gallery?

 

Please consider take a try with the following workaround:

Set the OnSelect property of the Gallery to following:

Set(currentItem, ThisItem)

 

Set the OnSelect property of the "Remove" button to following:

RemoveIf(
       [@'Rep 1 Test'], 
       ID = CurrentItem.ID
);
If(
    IsEmpty(
             Errors([@'Rep 1 Test'], CurrentItem)
    ), 
    Back()
)

or

Remove([@'Rep 1 Test'], BrowseGallery1.Selected);
If(
    IsEmpty(Errors([@'Rep 1 Test'])), 
    Back()
)

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Super User
Super User

Re: Limiting Data Visibility Based On User ID

If your Remove is outside the gallery (which I am assuming it is from what you put) you are not selecting an item in the gallery from the [@'Rep 1 Test'] anymore you are selecting an item from the collection. You just need to add a LookUp instead to find the item you are removing. Something like:

 

Remove(LookUp([[@'Rep 1 Test'], ID=BrowseGallery1.Selected.ID)

 

This is telling it to remove the item from your data source that has the same ID as the item in your gallery that is selected's ID.

 

Since you have the Back() part on the end it will refresh the collection when you come back to the screen BUT if you ever wanted it to do this action and stay on the same screen keep in mind that you would need to do that Remove, then a Refresh() of the data and then gather your collection again for it to update the items showing in the gallery. Not a big deal to do, and not needed hear but just figured it was worth mentioning. 

bmurphy1
Level: Powered On

Re: Limiting Data Visibility Based On User ID

@rebeccas 

The gallery is empty when you first open the app, but after you create a new contact and finalize it then all the previous contacts appear in the gallery.  How do I fix that?

Super User
Super User

Re: Limiting Data Visibility Based On User ID

It sounds like maybe after you create the new one and refresh your collection that you don't have the filter on that part also. Whatever you filter for to create the collection at the beginning you will need to do the same after the changes are made and you update your data. 

 

It is clearing and starting fresh so it won't know what you asked for before. 

Helpful resources

Announcements
thirdimage

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors
Users online (6,717)