Skip to main content

Formulas: Launch to self and Self operator

Headshot of article author Greg Lindhorst

Some long awaited features for Power Apps canvas formulas!

Launch to self

When run in a web browser, a canvas app can now replace itself with another canvas app or a web page.  This has been a long running community ask and also came up when we were created the COVID-19 Hospital Emergency Response solution where multiple apps hand off to one another.

To accomplish this, we have added a new way to use the Launch function.  Currently parameters are passed as a sequence of name value string pairs:

Launch( "https://bing.com/search", "q", "Power Apps", "format", "rss" )

Because this function can take an arbitrary number of arguments of any type that can coerce to a string, there weren’t a good ways to add an extra argument to specify the target tab for the launch.  The association between the parameter arguments is loose and can become confusing if there is a long list.

So we have added a new way to call Launch with a record instead of argument pairs.  With this form, the name and value of each parameter is far easier to associate:

Launch( "https://bing.com/search", { q: "Power Apps", format: "rss" } )

And with the addition, we can add a new parameter for the LaunchTarget:

Launch( "https://bing.com/search", { q: "Power Apps", format: "rss" }, LaunchTarget.Self )

And with that, shazam, you can now replace a canvas app with another canvas app or a web page.  Here’s the new functionality is shown in the COVID apps, note that browser window doesn’t change as we move between canvas apps:

Some important notes:

  • LaunchTarget only works with the new record syntax.  Adding it to the old format will have no effect.
  • LaunchTarget does not work in embedded apps, such as apps hosted in Power BI or SharePoint, and should be avoided.  We don’t have much control over how our host takes the request for a new window.  We may wall this off with our introduction of error handling to prevent confusion.

You can read more about all of this in the Launch documentation.

Self operator

At about the same time, but unfortunately not exactly the same time, we are introducing another fan favorite: the Self operator.

Formulas often refer to other properties of the same control.  Often you’d like to link two colors together, perhaps having the HoverBorderColor always have the same value as HoverColor.  If the control is Label1 then you would set the HoverBorderColor property to Label1.HoverColor.

That’s not horrible, but it could be better.  Let’s say you were copying and pasting that formula and the recipient control’s name is different; you would have to manually fix it up.  A relative reference would be a better way to go:  HoverBorderColor property set to Self.HoverColor.   Self is similar to the existing Parent operator.

Self vs. This

Why did we call this Self instead of This?  Both terms are used widely in computer languages and we debated this question at length.  Two main arguments for Self emerged:

  • We already have a Parent operator and some day we may want a Children operator in the future.  Self fits more naturally in to this hierarchy.
  • We already have ThisItem and will be shortly introducing ThisRecord. (coming soon) and ThisUser and ThisChannel are on the horizon.  If we had just a plain This, it would beg the question “This what?” as the others will all have a subject.  This*  is about data and not controls.

Self is fairly self explanatory (no pun intended), but some more coverage is coming soon to the Operators documentation.

Timing

Now the unfortunate part.  But it is only short term pain.

The changes for Launch were introduced first, before we knew were were going to add the Self keyword.   As is consistent with JavaScript’s Window.Open function, we went with LaunchTarget.Self for replacing the current window.

Unfortunately, adding a Self operator isn’t compatible with Self  as an enumeration value.  With the addition of the operator, Power Apps automatically puts single quotes around the ‘Self’ in LaunchTarget.’Self’.  Everything works fine, but it is ugly.

Realizing the name conflict, we have already started the process to change the name to LaunchTarget.Replace.  For good measure, we are also renaming LaunchTarget.Blank to LaunchTarget.New.  Although not an operator we already have blank as an important concept and someday perhaps it too will be an operator.

Such fun with names.  The short of it is that you may need to use Self, ‘Self’, or ultimately Replace as your LaunchTarget.   If you check the version number (Account in the Studio’s File menu) LaunchTarget.Self is available with version  3.20043 while LaunchTarget.’Self’ and the Self operator are available with version 3.20051.  There are many factors that control which version you might be using, including your region and cadence, so the easiest way to know which to use may be to type LaunchTarget and add the dot afterward to see the choices.

The good news is that your formulas will automatically move forward as we make these changes.  We have this nifty feature in Power Apps where we keep track of the version of the language you are using in your app and can automatically upgrade your formulas.