1

hope you are doing well. I am currently trying to custom format a list using JSON. I am having trouble conditionally displaying the "Attach" or paperclip icon depending on whether the field attachment link (i.e [$attachment_x0020_link]) is empty or not.

Below is the relevant code snippet and a the current look of the list

{
    "elmType": "a",
    "attributes": {
      "iconName": "=if([$attachment_x002d_link] != '', Attach)",
      "target": "_blank",
      "href": "[$attachment_x002d_link]"
    },
    "style": {
      "font-size": "15px",
      "padding-top": "15px",
      "cursor": "pointer"
    }

enter image description here

1
  • 1
    Is attachment link custom column you created in list? Or you are trying to read values from SharePoint default attachments column? Commented Nov 24, 2022 at 15:16

3 Answers 3

0

I don't think this is possible using JSON formatting. First of all, Attachments to a list item is an array of 1 or more objects, but you couldn't get hold of that property using @currentField. If you are planning to use Classic view, then you can probably get the attachments using REST API and use JS Link. This JS Link code snippet can help you to form your solution.

0

If attachment link custom column you created in your list, try using condition for iconName like below:

{
  "elmType": "a",
  "attributes": {
    "iconName": "=if([$attachment_x002d_link] == '', '', 'Attach')",
    "target": "_blank",
    "href": "[$attachment_x002d_link]"
  },
  "style": {
    "font-size": "15px",
    "padding-top": "15px",
    "cursor": "pointer"
  }
}

Where attachment_x002d_link is internal name of your SharePoint list column. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?

0

The attachment field is [$Attachments], and you can check whether it is populated by comparing it to 1 or 0:

{
  "elmType": "a",
  "attributes": {
    "iconName": "=if([$Attachments] == '0', '', 'Attach')",
    "target": "_blank",
    "href": "[$attachment_x002d_link]"
  },
  "style": {
    "font-size": "15px",
    "padding-top": "15px",
    "cursor": "pointer"
  }
}

Using the above, you should be able to at least get the icon to appear correctly.

However, it is not possible to get the file names/links directly using JSON. You might be able to find a potential workaround here: How can I add a link to list attachments using Json formatting

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.