Passing parameters to your Power Apps SharePoint form

We all know that it is possible to pass parameters to your Power Apps canvas apps, right?
But did you know that this is also possible for your Power Apps SharePoint forms?

In this blogpost, I will explain you how to do this.

Parameters

For those of you who haven’t played with parameters before, let me explain this shortly.
You can define parameters in your Power App by using the Param() function. You can then use this parameter in the URL of your Power App to use it, like this:

https://apps.powerapps.com/play/providers/Microsoft.PowerApps/apps/<APP_ID>?<PARAMETER>=<VALUE>

Please note that when you’re accessing the Power App as a guest, you need to provide your tenant ID as well:

https://apps.powerapps.com/play/providers/Microsoft.PowerApps/apps/<APP_ID>?tenantId=<TENANT_ID>&<PARAMETER>=<VALUE>

I’ve created a simple Canvas App to demonstrate this.
The Power App has a single label control that has its Text attribute set to Param(“parameter”), meaning I’m using a parameter called ‘parameter’ inside this app.

When I run this app without any parameters passed through the URL, I will just get a blank screen:

But when I pass the parameter, it will show up inside the label:

Please note that any parameter passed through is always a string. So if you want to pass through an integer, you need to convert the string to an integer using the Value() function:

Value(Param("parameter"))

Power Apps SharePoint form

Now that we know the basics of a parameter, we can proceed by passing it to our Power Apps SharePoint form.

The first thing you need to know is that you cannot pass parameters to the NewForm.aspx, EditForm.aspx and ViewForm.aspx forms inside SharePoint. The only way to do this is by using the URL of the Power App. But how do you know this URL? Your Power App forms do not show up in your App overview on https://make.powerapps.com.

The second thing you need to know is that when you do not load your Power App SharePoint form directly from SharePoint, your SharePointIntegration will not work and thus cannot use this directly for editing and viewing an item. You also need to configure a custom Save button, because the default Save and Cancel buttons will also not be loaded.

Getting your Power Apps SharePoint form URL

Actually, that’s pretty easy. A Power App always has an App ID. With this ID, you can use the URL as stated above (with or without parameters). For a canvas app, you can find this ID by simply going to the detail page of your app.
To find the App ID of your Power App form, you need to dig a little deeper:

  1. Go to your SharePoint list
  2. Enter list settings
  3. Go to Form settings
  4. Make sure that Power Apps is selected as your form handler and click on See versions and usage
  5. You will now be redirected to https://make.powerapps.com where you can find the App ID:

With this App ID, you can now put together the App URL of your Power Apps form.

Loading a specific item into your Power App form

When you open the URL you just put together, your Power Apps form will load, but is not related to any item inside your list. That’s why we always need to configure a parameter that contains the item ID so that we can load the corresponding item into the form by tweaking the Items attribute of your form a bit:

If(
    IsBlank(Param("ID")),
    SharePointIntegration.Selected,
    LookUp(
        testingFormParam,
        ID = Value(Param("ID"))
    )
)

If your ID parameter hasn’t been passed, the default SharePointIntegration will be used for loading your item. If the ID parameter has been passed through, a lookup to your list will take place using the ID parameter (converted from string to integer)

Using parameters in your DataCard

Now that we can load an item into our form, we can pass another parameter to be used for a specific SharePoint field in your form.
This can be done by changing the Default attribute of your DataCard to the following:

If(
    IsBlank(Param("ID")),
    ThisItem.parameter,
    Param("parameter")
)

If your ID parameter hasn’t been passed, the default value from the SharePoint field will be used. If the ID parameter has been passed through, the value of the “parameter” parameter will be used as a default value.

You can use as many parameters as you want. Be sure to separate them in the URL by using an ampersand (&) symbol and try to avoid special characters as your parameter value because that may break your Power App.

Saving items back to SharePoint

Your Power App also doesn’t contain the Save and Cancel button you are used to when you load your form directly from within SharePoint, so you need to add them as well and provide them with the correct OnSelect properties:

Save:

SubmitForm(<formname>)

Cancel:

ResetForm(<formname>)

Please note that RequestHide() functions will not work either, so if you want your form to be closed after Saving or Cancelling, you may want to add an Exit() or even a Launch() function.

Hiding the Office suite bar

By default, the Office suite bar is loaded on top of your Power App. You can disable this by adding ?HideNavBar=true to your URL. Make sure to add the first parameter using the ampersand symbol after that!

9 Replies to “Passing parameters to your Power Apps SharePoint form”

  1. For “Loading a specific item into your Power App form” where does the code go?(does it go under the app screen on the feature called “Onstart” that is confusing to me!

    0
    0
  2. Hello Ronald,

    Have you please achieved it? I am also looking for the same i.e. opening different NewForm screens based on the parameter.
    Can you please email me ( atiq_78@hotmail.com) the approach?

    Thanks a lot in advance,
    Atiq

    0
    0
  3. Hi Rick, above you mention the screenshot that shows the URL but I’m still confused… When clicking New in a SharePoint list (or double click an item to Edit it) the PowerApps form that you get does not launch from a URL that I can manipulate or am I missing something here?

    0
    0
    1. When using this solution, you cannot use the default New and Edit buttons in your SharePoint list because you cannot manipulate that URL. So you need to use the custom URL.
      I think it’s possible to redirect from the form (when clicking New or Edit) to the custom URL using the Launch() function on the OnStart or a timer control, but I haven’t tried that yet

      2
      0
  4. maybe i’m off track here… I got your url to work. It displays my form in “Power Apps” mode/view. I was looking for it to display it in Sharepoint Integration mode/view.

    I’m trying to pass a parm to Newform.aspx so I can display different screen or forms based on the parm using Sharepoint Integration. make sense?

    Thanks

    1
    0
    1. When using this solution, SharePoint Integration mode no longer works as you are no longer triggering the Power App form fromout SharePoint. That’s why you have to provide the item ID.
      If you want a specific mode to be triggered, you need to pass another parameter that will trigger your form into that mode (e.g. &Mode=New as a suffix to your URL, which triggers the Mode parameter). You can pass multiple parameters to make your Power App as dynamic as you want

      0
      0
    1. On the screenshot provided inside the ‘Using parameters in your DataCard’ paragraph, the URL is shown. Is that what you were looking for?

      0
      1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.