cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Beat
Level 8

OnStart vs OnTimerEnd function

I'm using a Timer with AutoStart true, Duration 600, and the following OnTimerEnd formula

 

If(Not(IsBlank(Param("ID"))),Navigate(DetailScreen1, Fade,
{device:LookUp('My List Name', ID = Value(Param("ID")))}))

Which works fine. Now I wanted to substitute this with the OnStart function of the screen, but it will always bring up the first item in the list. I had to revert to the OnTimerEnd solution. Now I have a few questions

1. What's the purpose of the timer duration?

2. What exactly is the usage of {device:LookUp... ?
3. Why does it work with OnTimerEnd but not with OnStart?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support Team
Community Support Team

Re: OnStart vs OnTimerEnd function

Hi @Beat,

 

I have made a test on my side, and don't have the issue that you mentioned.

 

Please check if you have passed proper ID parameter into your app. You could consider take a try to add a Label control within the screen of your app, set the Text property to following formula:

Param("ID")

then check if the ID parameter value is shown up well.

 

I also agree with @ChrisR's thought almost, you could consider take a try to save the retrieved record into a variable, and then use the variable within the Detail screen of your app rather than pass the retrieved record using Navigate function.

 

I have made a test on my side, please take a try with the following workaround:

 

  • Set the OnStart or OnVisible property fo the first screen of your app to following formula:
Set(device,LookUp('My List Name',ID=Value(Param("ID"))));
If(
!IsBlank(Param("Id")),
Navigate(DetailScreen1,ScreenTransition.Fade)
)
  • Set the Item property of the Display form within your Detail Screen to following:
device

 

 

Best regards,

Kris

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.

View solution in original post

ChrisR
Level 8

Re: OnStart vs OnTimerEnd function

This formula is inefficient.

 

Set(device,LookUp('My List Name',ID=Value(Param("ID"))));
If(
!IsBlank(Param("Id")),
Navigate(DetailScreen1,ScreenTransition.Fade)
)

I would not waste resources on an unnecessary lookup when Param() is obviously situational.  My original formula would only perform a lookup when a Param exists.

 

If(
   !IsBlank(Param("Id")),
   Set(vardevice,LookUp('My List Name',ID=Value(Param("Id"))));
   Navigate(DetailScreen1,ScreenTransition.Fade)
)

 

Beat,

 

What you did will work

If(!IsBlank(varDevice), varDevice, RequestGallery.Selected)

However, I personally would approach it a different way.  If coming from a link, with a Param, OnStart will populate varDevice and navigate to DetailScreen1.

 

If not, the user will be presented with the gallery screen.  Whichever control, in the gallery, that is used to navigate to DetailScreen1 would use the following formula... Assuming you still want to use a context variable.

 

Navigate(
    DetailScreen1, 
    Fade,
    {varDevice:BrowseGallery.Selected}
)

Now the form only needs varDevice in the Item property.  This might also give you the Item not Found you wanted with an invalid Param.

 

 

Chris - IW Mentor PowerApps Training

 

View solution in original post

8 REPLIES 8
ChrisR
Level 8

Re: OnStart vs OnTimerEnd function

1.  The Duration property dictates how long the timer will run, in milliseconds, before stopping and invoking the OnTimerEnd property.

2.  Navigate() has the ability to pass a Context variable to the next screen. In your formula, Navigate() is passing the Context variable device. The Context variable device is loaded with a record that is found using Lookup().

3.  I created a simple version of what your are trying to accomplish and I was able to navigate to the next screen and pass a context variable, loaded with a record, using the OnStart property.  I did not use the Param function, on this test, but in the past, I have succesfully used the Param function, in much the same way. 

However, I usually pass the record using a global variable, Set(), and not a context variable.

 

 

Hope it helps,

 

Chris - IW Mentor PowerApps Training

Beat
Level 8

Re: OnStart vs OnTimerEnd function

Thanks @ChrisR, I understand what the timer does, but not why one is needed. What do we have to wait for exactly?

The context variable "device" confused me a bit. So that could be anything, right?

In the meantime I figured out that with the OnTimerEnd it doesn't work either. It always navigates to the newest item in the list (which made me think it was working when I tested it...).

 

Can you give me an example of how you would use Set() in this scenario.

 

I am using URLs with the ?ID=n parameter in notification mails, so that a user who clicks on it gets directly to the detail screen of the record with that ID.

ChrisR
Level 8

Re: OnStart vs OnTimerEnd function

The timer is not really needed if you can get the OnStart to work.  Sometimes, the OnStart or Onvisible will not allow something so the timer is used as a crutch.  If you do end up using the timer, and want it to execute immediately, just put the formula in the OnTimerStart property.

 

Yes, you can name the context variable almost anything, however, your form is probably using the variable device in the Item property, so changing the name will cause this to break.  You might want to double check the forms Item proeprty to make sure it is correct.


Then I would check to make sure the parameter is passing correctly first.  Put a label on the first screen and set the Text to:

Param("ID")

Use the URL to launch the app and see if the ID is correct.

 

Then create a button, with the OnStart or Timer formula, and manually check that it functions.

 

The set command would look something like this:

 

If(
!IsBlank(Param("ID")),
Set(varDevice,LookUp('My List Name', ID = Value(Param("ID"))));
Navigate(DetailScreen1, Fade)
)

 

I changed device to varDevice, so the Form's Item property would need to follow suit.

 

 

Hope you get it figured out,

 

Chris - IW Mentor PowerApps Training

Community Support Team
Community Support Team

Re: OnStart vs OnTimerEnd function

Hi @Beat,

 

I have made a test on my side, and don't have the issue that you mentioned.

 

Please check if you have passed proper ID parameter into your app. You could consider take a try to add a Label control within the screen of your app, set the Text property to following formula:

Param("ID")

then check if the ID parameter value is shown up well.

 

I also agree with @ChrisR's thought almost, you could consider take a try to save the retrieved record into a variable, and then use the variable within the Detail screen of your app rather than pass the retrieved record using Navigate function.

 

I have made a test on my side, please take a try with the following workaround:

 

  • Set the OnStart or OnVisible property fo the first screen of your app to following formula:
Set(device,LookUp('My List Name',ID=Value(Param("ID"))));
If(
!IsBlank(Param("Id")),
Navigate(DetailScreen1,ScreenTransition.Fade)
)
  • Set the Item property of the Display form within your Detail Screen to following:
device

 

 

Best regards,

Kris

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.

View solution in original post

Beat
Level 8

Re: OnStart vs OnTimerEnd function

Many thanks @v-xida-msft this put me in the right direction. But when I set the Item property of the DisplayForm to the context variable varDevice, it would result in "No items found" when opening the DisplayForm without having submitted the ID parameter.

So I made the following tweaks

 

BrowseScreen1 OnStart property, clear context value setting it to blank

 

If(!IsBlank(Param("ID"))),Navigate(DetailScreen1, Fade,
{varDevice:LookUp('My List Name', ID = Value(Param("ID")))}), {varDevice:Blank())

DisplayForm1 Item property, varDevice if declared, but BrowseGallery.Selected if blank

 

If(!IsBlank(varDevice), varDevice, RequestGallery.Selected)

So that whenever there is no Param("ID"), varDevice is ignored. This works fine now, as long as the Param("ID") value is a valid ID in the list. In this case I would like to see "Item not found" or the like. How do I best achieve that?

 

 

ChrisR
Level 8

Re: OnStart vs OnTimerEnd function

This formula is inefficient.

 

Set(device,LookUp('My List Name',ID=Value(Param("ID"))));
If(
!IsBlank(Param("Id")),
Navigate(DetailScreen1,ScreenTransition.Fade)
)

I would not waste resources on an unnecessary lookup when Param() is obviously situational.  My original formula would only perform a lookup when a Param exists.

 

If(
   !IsBlank(Param("Id")),
   Set(vardevice,LookUp('My List Name',ID=Value(Param("Id"))));
   Navigate(DetailScreen1,ScreenTransition.Fade)
)

 

Beat,

 

What you did will work

If(!IsBlank(varDevice), varDevice, RequestGallery.Selected)

However, I personally would approach it a different way.  If coming from a link, with a Param, OnStart will populate varDevice and navigate to DetailScreen1.

 

If not, the user will be presented with the gallery screen.  Whichever control, in the gallery, that is used to navigate to DetailScreen1 would use the following formula... Assuming you still want to use a context variable.

 

Navigate(
    DetailScreen1, 
    Fade,
    {varDevice:BrowseGallery.Selected}
)

Now the form only needs varDevice in the Item property.  This might also give you the Item not Found you wanted with an invalid Param.

 

 

Chris - IW Mentor PowerApps Training

 

View solution in original post

Beat
Level 8

Re: OnStart vs OnTimerEnd function

I think I did try setting varDevice: BrowseGallery.Selected, which seemed just logical, but it didn't work.

Now I just realized that some things only work properly when you launch the app, not using the Play button.

Will give this definitely a try and let you know. Thanks for the prompt responses, great experience @ChrisR

Beat
Level 8

Re: OnStart vs OnTimerEnd function

@ChrisRworked like a charm, thank you!

Helpful resources

Announcements
thirdimage

Power Automate 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

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 110 members 5,097 guests
Please welcome our newest community members: