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>

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!

Leave a Reply

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