Skip to content

Custom attachments column

Fedes365 edited this page Nov 1, 2022 · 38 revisions

THE ATTACHMENTS ICON: AN OLD STORY

Since SharePoint classic experience, attachments have always been under debate among experts and users: those who find them useless and a bad practice, those who actively use them... and those who "it depends". In any case, even though some custom solutions allowed to partially overcome the existing limitations – as suggested here and here – the (in)famous attachments column and its icon were basically the "Out Of The Box" available feature to communicate if one or more files were added to an item list or not.

A lot of things have changed since then. Microsoft Lists is increasingly packed with great new features and the new split operator makes possible to implement a better user experience, when it comes to use attachments in a list.

Change the OOTB attachments icon

Since the attachments column is now supported by JSON formatting, the easiest way to improve the OOTB icon visibility is to replace it with a new and better one. To make this work, we'll have to insert a custom JSON code into the formatting box of the attachments column. Because the attachments column is not listed among the other columns (such as Modified, Created and so on), here is a trick: in the list settings, click on any column name, for example "Modified" and on the address bar replace what's after &Field= with Attachments. See the sample image below 👇

This workaround will allow us to open the OOTB Attachments column settings to paste a custom JSON code available HERE into its column formatting box:

After applying the custom JSON code, the OOTB Attachments column should have a new icon displayed (if one or more attachments are added to an item):


Create a new custom Attachments column

Thanks to the new split operator of JSON custom formatting and a Power Automate flow, we can change the user interface and thus the corresponding user experience for attachments in Microsoft Lists. Here are the steps required, including the Power Automate flow. Let's say that we have already an existent list with some items and attachments added to them:

1) COLUMN CREATION: Go to your list and create a new multiple lines of text column and name it LIST_ATTACHMENTS

2) COLUMN FORMATTING: Click the column name -> Column settings -> Format this column -> Switch to advanced mode. Copy the JSON code provided here and paste it into the column formatting box as shown in the image below:



3) LIST NAME REPLACEMENT: go to line number 74 of the JSON code and replace the dummy text with your real list name, as shown in the image below:

⚠️ Warning: the real list name is the one you can find in your browser address bar! Therefore, if you have created a list named "Contoso Products", then you have to copy the coded name in the address bar, that is "Contoso%20Products":

POWER AUTOMATE FLOW

This additional tutorial will help you create a flow to get the attachments when added to a record. This process is mandatory, given that it writes into the custom attachment column previously created and the custom JSON code translates it to clickable labels.

HOW IT WORKS

A Power Automate flow uses a service account (or a personal account not meant for actual use of this solution) to check if one or more attachments are added to an item. This flow is triggered every time a new item is created or modified by other users.

Here is an overview of the Power Automate flow:

HOW TO AVOID INFINITE LOOPS

At this point you may have noticed something weird: if a Power Automate account updates an item with all its attachments labels, then the trigger will run again, given that the item has been modified. This behaviour would lead to an infinite loop, where this flow would run again... again... and again just because the service account is doing what we setup!

How to prevent this unwanted behaviour?

As explained in a tutorial made by Reza Dorrani, you have to setup a trigger condition. In my example, the trigger condition checks if the item has been modified by a service account used to run the flow. If yes, the trigger condition will automatically stop the flow, then avoiding infinite loops.



<<HEY, WAIT A MINUTE... WHAT'S THE SPLIT OPERATOR AND HOW DOES IT WORK?>>

💡 You can find out more about the split operator in a detailed article written by Michel Mendes and an amazing implementation shared by Tetsuya Kawahara.