Starting a flow from a SharePoint list or library for a user with read permissions

Share the love

There are many cases where you might need a user with read permissions to start a Power Automate flow from a SharePoint list or library. However, if the user has anything below contribute permissions on that list/library, they won’t see the option to start the flow under the Power Automate menu.

I ran into this issue recently when I wanted a user to have the ability to start a review on a document, however, as they had read access on the library, they weren’t able to do so.

I decided to use Power Apps to get around this problem. I created a canvas Power App with a form connected to my SharePoint library. I am planning on passing in the ID of the item from the SharePoint library through the URL. I talk about passing in parameters to a Power App in a previous post. On the OnVisible property on my home screen, I set my passed in ID parameter.

Set(
    varDocID,
    Value(Param("ID"))
);

Now we need to filter the form to show the item the user has selected from the hyperlink (which we will create later in the post). Select your form, and on the Item properties, filter the data to equal the ID of the passed in parameter.

First(Filter('Shared Documents',ID=varDocID))

You can add any fields you like in your form. I added a number of view-only fields and one field that is not connected to the SharePoint document properties, but will be sent to the reviewer; I added a text field for comments.

Along with the other fields in my form, I have also included the Folder Path of the document. However, I have set the Visible property of the data card to false so you can’t see it on my form, but I can still reference the data. This will be used in a Back button which we will come to next.

I added a button that is not visible to the user until they submit the form. This will be the back button and will take them back to the SharePoint library. Add the button to your screen.

Go to the OnVisible property of your home screen and create a context variable. This will allow us to show and hide the back button when we want to.

UpdateContext({varBack: false});

Now go to the Visible property of your Back button and set it to the varBack variable. As it is set to false when a user first opens the app, the back button will not be visible.

varBack

Go to the OnSelect property of the Back button to write a Launch command to send the user back to SharePoint. We know where the user was previously before launching the app as we have the folder path.

Launch("https://<siteURL>" & HmeScn_txtFolderPath.Text,{},LaunchTarget.'Self');

Let’s jump over to Power Automate and create the flow that will connect to the Power App. Firstly, initialize the variables you want to use in your flow. I’m using the ID, comments and the user’s email address. Set the value of the variables to Ask in Power Apps.

From here you can configure your flow as you normally would have if the user was able to start the flow from the SharePoint library. However, as we are starting our flow from Power Apps, we need to join this flow up to our Power App. Save your flow and go back to Power Apps.

As you would have seen from my screen shot above, I have included a Start Review button on my screen. This button will start my flow. Select the button and go to the menu. Click Action > Power Automate. Select the flow you created earlier. You will need to pass in the variables you initialized in your flow. From my example, my code would be:

'ReviewfromPowerApp'.Run(HmeScn_txtDocumentNumber.Text,HmeScn_txtComments.Text,User().Email);

I would also like to show the Back button to the user now that they have submitted the form. Directly under the code above, write:

UpdateContext({varBack: true});

Finally, we need to add the link to the SharePoint document library so the user can start the flow. I created a column in the library that I use for a hyperlink. It is just a Single line of text field.

Select the column you want to use as a hyperlink, and choose Column settings > Format this column. On the flyout, choose advanced settings. The JSON that I use on the column formatting looks to another column called Document Review Status. If a document review is already ‘in Progress’ or the Content Type is a folder, the hyperlink will not show.

{
  "$schema": "https:developer.microsoft.com/en-us/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "style": {
    "color": "#0078d7"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "iconName": "WorkFlow"
      },
      "style": {
        "visibility": "=if(indexOf([$DocumentReviewStatus], 'in Progress') != -1,'hidden', if(indexOf([$ContentTypeId], '0x0120') >= 0,'hidden','visible'))"
      }
    },
    {
      "elmType": "a",
      "style": {
        "border": "none",
        "background-color": "transparent",
        "color": "#0078d7",
        "cursor": "pointer",
        "text-decoration": "none",
        "padding": "6px",
        "visibility": "=if(indexOf([$DocumentReviewStatus], 'in Progress') != -1,'hidden', if(indexOf([$ContentTypeId], '0x0120') >= 0,'hidden','visible'))"
      },
      "txtContent": "Start Review",
      "attributes": {
        "href": "='https://apps.powerapps.com/play/<PowerAppsGUID>?tenantId=<TenantID>&ID=' + [$ID]"
      }
    }
  ]
}

It is likely that Microsoft will allow read only users to start flows in the future as it is feature that has been voted for on the User Voice forums. However, for now, this can be a workaround.


Share the love

Leave a Reply

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