Add a button in to a SharePoint List/Library to trigger a Flow (part 02-customization)

Part 02 (This article)

In my previous article, we saw how we can add a button in to SharePoint online list or library to trigger a flow in place. We are continuing with this article on how we can customize the newly added button to change its appearance (Well, let’s make it look like a button).

bc368f944e446068509494a3123d91d7

Changing the appearance:

Go to the format mode from the target button column. And we can use the following parameters to change the look and feel. My button here looks good as it stands out from the rest of the content in this space.

  • txtContent: “Define your button text”
  • color: “set a button text color code”
  • border: “set a border to the button”
  • background-color: “set a button background color”

last_thumb[2]

Applying a condition to the button:

Further more, you can customize the button to apply when a condition is true (e.g. – show a button only when the Flow have not started).

In this case, I’m going to tweak my approval Flow a little bit to maintain the status of the library items. The purpose here is to update the status of a item which is initiate for approval but still “Pending” as we using a custom status column here.

Tue4

By modifying the Approval Flow, I am adding a new step (SharePoint Update item action) to my existing flow. This new step has to be placed before the starting the start. At this stage, I have to set the status as “Pending” (static string).

ast

Then the same action added to both ending paths in order to update the status column up on “Rejection” or “Approval”. At this stage I can simply use the “Response” variable to pick up the current status value and update the “Status” column.

Tue3

Once added, it’s position looks like below.

Tue1

Define the Site URL, Choose the target library, pick the ID attribute and Response variable as shown below. Repeat the same for “No” path as well and that’s all we need to do here.

Tue2

That’s it from the Flow and we can head back to the Library to do the appearance tweaking. Go the column format mode and notice the changes I have done here. Apart from the color and background changes which I did to the button earlier, I have added a condition to display the button only when its true. Under this logic, the button would only appear when the status column = empty (“”), meaning the Flow have not started for a respective item in this library.

Tue5

And, as expected ! the logic is right therefore the condition perfectly applies. I have few documents in this library with mixed statuses (Rejected, Approved, Pending and of course some are not started yet). The button only showed for the items which are not gone through the Flow.

Tue6

Microsoft reference for JSON based column formatting is here. This article has covered many perspectives of column formatting.

And ! here’s the full JSON code of this customization which you can reuse if you have a similar use case.

If you want to start from the beginning, go ahead and read my previous article.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "style": {
    "color": "#0078d7"
  },
  "children": [
    {
      "elmType": "button",
      "style": {
        "border": "light",
        "background-color": "yellow",
        "color": "#0078d7",
        "cursor": "pointer",
        "visibility": {
          "operator": "?",
          "operands": [
            {
              "operator": "==",
              "operands": [
                "[$Status]",
                ""
              ]
            },
            "visible",
            "hidden"
          ]
        }
      },
      "txtContent": "Send to Approval",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"e290feff-0013-41f2-97dd-91a37fb84ea0\"}"
      }
    }
  ]
}

Add a button in to a SharePoint List/Library to trigger a Flow (part 01)

Part 01 (This article)

Microsoft Flow together with PowerApps undoubtedly revolutionizing the process automation in modern work places. You may have a Flow attached to a document library or list but there is no easy access to initiate that flow from the list/library itself. People have to dig in a little bit to initiate it and that’s a little bit of time consuming for constant usage.

clip_image001

With this article, we will find out how we can overcome this struggle using a little bit of JSON stuff (Don’t worry about that word, you don’t need to be a developer here). Using the Modern SharePoint capabilities, we can embed a button right in front of every item in a list or library so that people can trigger a Flow right there. New column formatting is a cool out of the box capability to get this done.

Now let’s get this started. First and foremost, you need to have a Flow created in place and have the GUID of it.

We’ll get a Flow created really quick in case if you don’t have one. If you have a Flow already in place, you can skip these basic steps

Open up your SharePoint Library and click on the “Flow” drop down on the ribbon as below. Then go to “Create a Flow

1

You’ll see a list of available templates. You can utilize these templates if your requirement matches with them. Or simply feel free to create your own. Thankfully, there are a lot of templates published by Microsoft and the community which you can re-use on various scenarios. Unless the requirement is very specific or you are really keen on creating one your own, there is no point of designing a Flow from the scratch.

2

I am adding a simple “Request Manager Approval” flow here. Pretty straight forward.

4

Next, go ahead and check if the flow is added to “My Flows” section. If so, you are good to go.

5

Now go inside the created Flow by clicking on it and copy the highlighted GUID form the address bar of your browser. We need this for our new Button.

6

https://asia.flow.microsoft.com/manage/environments/Default-f50d518a-e13c-4359-85f6-ef76484f4c32/flows/e290feff-0013-41f2-97dd-91a37fb84ea0/details

Now to add the button but before that we need a new column for this button. From the list or library, go to the very end horizontally and add a new text column to this list/library.

10

11

It should be like below after adding. You can edit this view by dragging and dropping the desired column across the library if you wish to. I’m calling mine “Approval” so it makes scenes for a column contains buttons.

a

Now, go ahead and format this column. Click on the little arrow on the newly created column and go to format mode.

b

And paste the JSON code below. replace the GUID using the target flow which you have copied to the clip board.

c

Here’s the code (you will have it provisioned as you go to format mode itself).

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "span",
  "style": {
    "color": "#0078d7"
  },
  "children": [
    {
      "elmType": "span",
      "attributes": {
        "iconName": "Flow"
      }
    },
    {
      "elmType": "button",
      "style": {
        "border": "none",
        "background-color": "transparent",
        "color": "#0078d7",
        "cursor": "pointer"
      },
      "txtContent": "Send to Approval",
      "customRowAction": {
        "action": "executeFlow",
        "actionParams": "{\"id\": \"e290feff-0013-41f2-97dd-91a37fb84ea0\"}"
      }
    }
  ]
}

That’s it and you will immediately notice the button applied to your column. This is how my library looks like after adding the button. It still doesn’t look like a button because of the border, background and colors of it.

14

Cool thing is ! you can customize the button to look like as you want it to be. Further more, you can also make it a logical button which has a condition behind it. (e.g. – show a button only when an item pending for approval).

Read the part 02 of this article series to further customize the button and apply conditions.

Detailed Microsoft article for this is here

DISCLAIMER NOTE: This is an enthusiast post and is not sponsored by Microsoft or any other vendor.