I've been looking into the new nice JSON column formatting functionality in SharePoint Online.
I cannot find a way to include values from other columns in my display result. This should be a very common scenario, e.g. formatting the title field based on the value of a status field instead of having to display the status field and format that field.
But as far I can see there is no support to get data from another field of the current item in the formatting declaration. In all examples "txtContent": "@currentField"
is used. I would love to be able to access "@currentItem"
or similar.
Am I missing something? I cannot see how custom JSON formatting could help me either.
Update:
After looking carefully into this example I could get some examples working: Augment People fields using column formatting in SharePoint. But it seems to be pretty shaky for now.
Here is a list as of 2018-01-17 of what I can make work and what doesn't work:
Works
{
"elmType": "div",
"txtContent": "[$customField]"
}
{
"elmType": "div",
"txtContent": "[$FileLeafRef]"
}
{
"elmType": "div",
"txtContent": "[$File_x0020_Type]"
}
{
"elmType": "div",
"txtContent": "[$SomeParentTextColumn]"
}
Does not work
{
"elmType": "div",
"txtContent": "[$Title]"
}
{
"elmType": "div",
"txtContent": "[$SomeParentChoiceColumn]"
}
I haven't tested too much, but the problematic fields seems to be:
- Some internal SharePoint fields, e.g. Title
- None-text fields (maybe those who involve some lookup mechanism) that are defined not directly in the library but declared e.g. on the Site Collection Level (
$SomeParentChoiceColumn
in the example above)
Update 2018-07-24:
Answered by a member of the Microsoft SharePoint organization in an issue in the sp-dev-docs github repo.
You are only able to reference other columns that are being returned by the view (The ID is always returned even when not shown). This is because the formatting is applied on the client side and no additional retrieval is done beyond the initial view results.
This also explains the weird behavior you were seeing where it temporarily worked when opening the panel since this was retrieving the additional information which then makes it available to formatting.
@currentField
, try with the field's internal name and check. Should work