Forum Discussion

James_L's avatar
James_L
New Member
7 years ago

SharePoint List View Formatting with JSON: How to show if entry has attachment or not

Hello

 

I am currently developing a dashboard by editing a Sharepoint List view with JSON and trying to figure out how to show if an entry has an attachement or not.  In the code below I have a checkbox field for "savings" that performs what I want, but I can not get the "Attachements" field to do the same. Currently every entry shows the "X" value regardless if it has an attachement or not.

 

{
"elmType": "span",
"attributes": {
"class": "=if([$Savings] == True, 'ms-fontColor-white ms-bgColor-green ms-fontSize-l','')"
},
"style": {
"border-radius": "50%",
"vertical-align": "text-bottom",
"margin-left": "25px",
"line-height": "2em",
"padding-left": "8px",
"padding-right": "8px",
"padding-bottom": "2px"
},
"txtContent": "=if([$Savings] == True, '$',''"
},
{
"elmType": "span",
"attributes": {
"class": "=if(toString[$Attachments] == '', 'ms-fontColor-white ms-bgColor-black ms-fontSize-l','')"
},
"style": {
"border-radius": "50%",
"vertical-align": "text-bottom",
"margin-left": "25px",
"line-height": "2em",
"padding-left": "8px",
"padding-right": "8px",
"padding-bottom": "2px"
},
"txtContent": "=if(toString[$Attachments] == '', 'X', '')"
}

 

Thank you for your help!

 

2 Replies

  • v-xicai's avatar
    v-xicai
    Community Support

    Hi James_L ,

     

    You can try to change it like code below( Pay attention to the red font words ), go through the link to learn more : https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting .

     

    {

    "elmType": "span",

    "attributes": {

    "class": "=if([$Savings] == True, 'ms-fontColor-white ms-bgColor-green ms-fontSize-l','')"

    },

    "style": {

    "border-radius": "50%",

    "vertical-align": "text-bottom",

    "margin-left": "25px",

    "line-height": "2em",

    "padding-left": "8px",

    "padding-right": "8px",

    "padding-bottom": "2px"

    },

    "txtContent": "=if([$Savings] == True, '$','')"

    },

    {

    "elmType": "span",

    "attributes": {

    "class": "=if([$Attachments] == True, 'ms-fontColor-white ms-bgColor-black ms-fontSize-l','')"

    },

    "style": {

    "border-radius": "50%",

    "vertical-align": "text-bottom",

    "margin-left": "25px",

    "line-height": "2em",

    "padding-left": "8px",

    "padding-right": "8px",

    "padding-bottom": "2px"

    },

    "txtContent": "=if([$Attachments] == True, 'X', '')"

     

    Best Regards,

    Amy

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • James_L's avatar
      James_L
      New Member

      Thank you for the attempt v-xicai . Unfortunately this did not work.

       

      Below are variations I've attempted with no success (Does not include variations resulting in an error). Also note i have tried adding "toString" to all of these.

       

      1. "=if(toString([$Attachments]) == '', 'X', '')"

      2. "=if([$Attachments] == True, '', 'X')"

      3. "=if([$Attachments.fileName] == '', 'X', '')"

      4. "=if([$Attachments.value] == '', 'X', '')"

      5. "=if([$Attachments.title] == '', 'X', '')"

      6. "=if([$Attachments] == 'Yes', '', 'X')"

      7. "=if(toString([$Attachments]) == 'Yes', '', 'X')"

      8. "=if(toString([$Attachments.lookupValue]) == 'Yes', '', 'X')"

       

      regards

      James