5

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.

4
  • Instead of @currentField , try with the field's internal name and check. Should work Jan 17, 2018 at 10:26
  • Thanks Mohamed, but I cannot get it to work. So I've tested: { "elmType": "div", "txtContent": "@title" } and: { "elmType": "div", "txtContent": "@customfield" } But I only get it to display the exact text "@title" This will display empty: { "elmType": "div", "txtContent": @title }
    – Gil Roitto
    Jan 17, 2018 at 12:02
  • I can make it work, but it seems very shaky, e.g. Title and some other fields does not work, while some does.
    – Gil Roitto
    Jan 17, 2018 at 13:05
  • In case you had the same problem as me, column names are whatever was the initial column name, even if the field name was changed. Also, it just removes spaces. In my case: Original Field Name = "Primary HEX", json variable = [$PrimaryHEX]. Perhaps given time to update, the changed name might work too, but I was changing it and testing immediately. Mar 16, 2021 at 22:18

2 Answers 2

4

I've also come across this issue, and although I don't claim any particular expertise, it appears that you need to have the referenced field available to the selected view.

Paul CJ

1
  • Yes, it is correct. Read more about the issue in the sp-dev docs github repo link.
    – Gil Roitto
    Jul 24, 2018 at 9:24
0

I have a similar issue. When formatting a "Person" column called "Owner"

  "elmType": "div",
  "txtContent": "@currentfield.title"

Works and

  "elmType": "div",
  "txtContent": "[$Owner.title]"

Works, but

  "elmType": "div",
  "txtContent": "[$RaisedBy.title]"

doesn't work - despite the field called "RaisedBy" being a "Person" column too, and is displayed in the view.

This inconsistency is the case for attempting to pull in various other values using JSON. What is the logic that I'm missing?

(I can pull in some text field values (but not other text field values). I can't pull in any number field values. I can't pull in Calculated fields. All fields are visible in the current view.)

1
  • Check the internal column names. The fields need to be in the view and referenced using their internal names. Jun 7, 2019 at 13:22

Your Answer

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

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