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

Powerapp - screen navigation with current user email

Hello all,

 

I have created a canvas powerapp. when I click Continue button it should navigate to the editscreen and with current user login item should show.

Note: here for one user only one request - no more than one request entered by the user.

how can I achieve that?

I tried using below:

 

Navigate(EditScreen, ScreenTransition.None, {displayItem:Form1.LastSubmit}) 

 

I need the filter with current user email.

 

example: it's showing the last item submitted. but if  user2 submitted the request lastly, then for the user1 also sees the last submitted on only. 

 

please help..

 

Thanks,

Saanv

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Saan ,

My apologies - I was really giving some guidance on how to approach things. I will now try to explain the logic.

Firstly, the code I gave returns the last record the current user has posted

 

FirstN(
   Sort(
      Filter(
         'VendorList',
         <UserEmail>=vEmail
       ),
   ID,
   Descending
   )
)

 

This is the record the user saved last, however it returns a table with one record (the one you want) in it.

The other thing you need to do to avoid "Delegation" issues is to set a Variable for the User's email - this can be done at App start, but I will do it before the screen transition below.

The last bit is that the resulting record has to be in the Items property of the form with one more trick - because it is a table, you have to tell PowerApps which record to display. As you know there is only one, you use the first. So Putting it all together:

Your transition to the screen

 

Set(
   vUserMail,User().Email
);
Navigate(
   EditScreen, 
   ScreenTransition.None
)

Now the Items property of the form on the screen should be

First(
   FirstN(
      Sort(
         Filter(
            'VendorList',
            'Created By'.Email = vUserMail
          ),
      ID,
      Descending
      )
   )
)

 

So to put some logic around this (you have to read formulas from the inside first):-

  1. You are filtering the Vendor List to show only records the current user has created
  2. You then sort that list by ID descending
  3. You then take the first record in this set (which of course is the last one written)
  4. You then send the table to the form and tell it to display the first record (as it will not display a table - that is what galleries are for)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more. It also closes the item.

View solution in original post

5 REPLIES 5
WarrenBelz
Super User
Super User

Hi @Saan ,

I assume you have the user's email in the table.

LastSubmit will get the last record (as you have stated), however you might try this.

Set a variable for the user's email (this avoids delegation issues.

UpdateContext({vEmail:User().Email})

Filter the records the user has done by ID descending, then get the first one, which is the last one posted by the user.

FirstN(
   Sort(
      Filter(
         <YourList>,
         <UserEmail>=vEmail
       ),
   ID,
   Descending
   )
)

NOTE: If the user has created less than 2000 records, you could Collect the Filter bit and then Sort/FirstN the collection

 

If this post helps, then please consider Accept it as the solution to help the other members find it more. It also closes the item.

 

Hello @WarrenBelz 

 

Thanks for the reply.

 

I have tried like below.

Navigate(EditScreen, ScreenTransition.None, FirstN(Sort(Filter('VendorList',User().Email= 'Created By'.Email),ID,Descending)))

 

But the error is: Function navigate has some invalid arguments.

 

My complete goal of this: the user hits on my gallery and item arrow it show redirects to that particular view: thisitem. 

instead of that when my user clicks on Continue button it needs to directly go to item (as every user has one and only one item) by eliminating the step of navigate(Myitems, none).

 

Now:

Continue button --> My item gallery(contains only one item for every user) -- > click on gallery item arrow --> navigates to edit item of that edit screen

I need:

Continue button -->navigates to edit item of that edit screen

 

Thanks 

Saanv.

All,

 

Can any one guide me on this, kind of lil urgent

 

Many thanks for your help in an advance!!!

 

Saanv

Hi @Saan ,

Sorry I did not see your last post - I will have a look now

Hi @Saan ,

My apologies - I was really giving some guidance on how to approach things. I will now try to explain the logic.

Firstly, the code I gave returns the last record the current user has posted

 

FirstN(
   Sort(
      Filter(
         'VendorList',
         <UserEmail>=vEmail
       ),
   ID,
   Descending
   )
)

 

This is the record the user saved last, however it returns a table with one record (the one you want) in it.

The other thing you need to do to avoid "Delegation" issues is to set a Variable for the User's email - this can be done at App start, but I will do it before the screen transition below.

The last bit is that the resulting record has to be in the Items property of the form with one more trick - because it is a table, you have to tell PowerApps which record to display. As you know there is only one, you use the first. So Putting it all together:

Your transition to the screen

 

Set(
   vUserMail,User().Email
);
Navigate(
   EditScreen, 
   ScreenTransition.None
)

Now the Items property of the form on the screen should be

First(
   FirstN(
      Sort(
         Filter(
            'VendorList',
            'Created By'.Email = vUserMail
          ),
      ID,
      Descending
      )
   )
)

 

So to put some logic around this (you have to read formulas from the inside first):-

  1. You are filtering the Vendor List to show only records the current user has created
  2. You then sort that list by ID descending
  3. You then take the first record in this set (which of course is the last one written)
  4. You then send the table to the form and tell it to display the first record (as it will not display a table - that is what galleries are for)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more. It also closes the item.

View solution in original post

Helpful resources

Announcements
User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,383)