Is it possible to have a link to attachments using json formatting?
I want my users to be able to click a link to go the the attachment file from a view and not have to edit or click on the form to see the attachments.
Unfortunately, the attachments field is not directly accessible in JSON formatting.
You can only check if attachments are available or not for the list item using:
"txtContent": "=if([$Attachments] == '0', 'no attachment', 'item has attachment')"
Source: Conditional formatting if list item has attachment
However, if you have the filename stored in one of the columns in list, you can build a link to the attachment using JSON formatting like:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "button",
"style": {
"border-radius": "5px",
"margin": "5px 0px",
"padding": "0px",
"visibility": "=if([$Attachments] == '0', 'hidden', 'visible')"
},
"attributes": {
"class": "ms-bgColor-themePrimary"
},
"children": [
{
"elmType": "a",
"txtContent": "Attachments",
"style": {
"text-decoration": "none",
"padding": "10px 0px",
"width": "100%"
},
"attributes": {
"href": "= @currentWeb + '/Lists/ListName/Attachments/' + [$ID] + '/' + [$FileName] + '?web=1'",
"target": "_blank",
"class": "ms-fontColor-white"
}
}
]
}
Output:
Similar thread: Clickable href with the attachments