Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
James_L
New Member

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', '')"
}image.png

 

Thank you for your help!

 

2 REPLIES 2
v-xicai
Community Support
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.

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.