Button in SharePoint list to trigger PowerAutomate/Flow – a few tweaks 

The situation

I have a SharePoint list which holds information for generating data sharing contracts with external partners.

I have a Flow linked to this that sends the data from the selected item over to Adobe Acrobat Sign to insert into a template, and then send out for electronic signature.

Screen shot of a menu option saying "Data Sharing:  Generate Contract & Request Signature"

Can it be improved?

I’m often asking “is this good enough?” and “could it be improved?”. Usually the answers are “maybe” and “probably”!

The current setup works well for me – I know how to use it and it’s fairly swift.

However, it’s not very “discoverable” for others – so if I’m not available someone can’t just pick-it up and work it out themselves:

  • They need to be told to select an item in the list before doing anything
  • Then click “Automate”
  • Then <wait a moment for the Flow trigger to appear>
  • …then click “Generate Contract”

Wouldn’t it be great if there could be a visible button in the list that someone could click to trigger the Flow for that row?

“Surely I’m not the first to want this…”

Often someone has already worked out a way to do what you want – and credit to Laura Rogers who has an excellent write-up of exactly this requirement. With a small bit of JSON you can format a column in a SharePoint list to display either a hyperlink or a button to trigger a Flow.

I won’t repeat what she’s already covered – but I have added a few tweaks to suit my purposes.

In Laura’s write-up she puts in some conditional formatting so that a button only shows if the approval status of the item is “pending”. This won’t work for my situation – however I do have a column showing the Adobe contract status (“OUT FOR SIGNATURE”, “SIGNED” etc).

My Tweaks

If there’s no status, that means it hasn’t been sent to Adobe – so we want the button to show. As soon as there is a status I don’t want the button any more.

This can be done with some JSON setting the visibility to be dependant on an If statement:

"style": {
    "visibility": "=if([$Contract_x003a_AgreementStatus]=='','visible','hidden')"
  }

The result

Using Laura’s guide to create a button in a column and adding in conditional visibility gives me a button that only shows if a contract hasn’t already been generated:

Screenshot showing a Sharepoint list. A "Generate Contract" button appears on the first row, with nothing in the "Contract" or "Contract Status" columns.  Subsequent columns don't show a button, but do have something in the "Contract" and "Contract Status" columns.

Can it be improved?

Probably!

When using this something didn’t quite feel right – the “button” didn’t “feel” like a button.

Eventually I worked out the reason for this feeling – there wasn’t a visual cue when moving the mouse over the button – and that was causing the “it’s not a button” feeling.

Animation of mouse moving over a button, without a change in mouse cursor

More JSON!

An extra bit of JSON will change the mouse cursor to a pointer – signalling that this is a clickable element:

  "style": {
    "visibility": "=if([$Contract_x003a_AgreementStatus]=='','visible','hidden')",
    "cursor": "pointer"
  }

Yes, much better!

Animation of mouse moving over a button, with mouse cursor changing to a pointer

Putting it all together

This is the JSON I’m using to format the SharePoint column to give me:

  • A clickable button…
  • …that launches a Flow…
  • …that only appears when there’s not already a contract…
  • …that changes mouse cursor on mouse-over

And here it is all together:

{
  "_Source": "Based on https://wonderlaura.com/2018/07/18/button-in-sharepoint-list-to-trigger-microsoft-flow/",
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "txtContent": "Generate Contract",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"<RedactedFlowID>\"}"
  },
  "style": {
    "visibility": "=if([$Contract_x003a_AgreementStatus]=='','visible','hidden')",
    "cursor": "pointer"
  }
}

An added bonus – I’ve put in an extra JSON element (that’ll be ignored) to add in notes about where this JSON came from – to help anyone that looks at this in the future.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: