Get value of Name column from SPO list for JSON formatting
-
08-02-2021 - |
题
First of all, apologies if this horse has been beaten before but I can't find anything so far to help me out.
I'm trying to do some conditional formatting of a column in a SP list.
One of the columns in the list is Name (it would appear that this is a default column name). For whatever reason I'm unable to get the following JSON to see a Name column. I've tried [$Name]
, which 'seems' like it should work, but even though there is a Name value in each row of the list, the JSON is never picking it up.
Can someone throw me a bone here?
Here's a JSON snippet of what I'm attempting:
{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "a",
"txtContent": "=if(indexOf(toLowerCase([$Name]),'pink') != -1, 'STATUS REPORT','')",
"style": {
"color": "blue"
},
"attributes": {
"target": "_blank",
"href": "=if(indexOf(toLowerCase([$Name]),'pink') != -1, <someurl>, '')"
}
}
解决方案
According to the official documentation,
You can use this context(
[$FieldName]
) to reference the values of other fields within the same row by specifying the internal name of the field surrounded by square brackets and preceded by a dollar sign:[$InternalName]
.
So, you need to use the internal name of your Name
column in your JSON code.
Check below URL to find out the internal name of SharePoint column:
Find the internal name of SharePoint column.
Note: If you are trying to use Name
(filename) column in document library then its internal name is FileLeafRef
. So you can use it like:
{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "a",
"txtContent": "=if(indexOf(toLowerCase([$FileLeafRef]),'pink') != -1, 'STATUS REPORT','')",
"style": {
"color": "blue"
},
"attributes": {
"target": "_blank",
"href": "=if(indexOf(toLowerCase([$FileLeafRef]),'pink') != -1, 'https://www.google.com', '')"
}
}