0
votes

I have the following code given by Michael Han that is working just fine. It formats a number like '2030' to be '20:30'

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": {
    "operator": "+",
    "operands": [
      "=substring(toString(@currentField),0,2)",
      ":",
      "=substring(toString(@currentField),2,4)"
    ]
  }
}

I need to use this column as a lookup column for another list, so I pasted this code and replaced @currentField with @currentField.LookupValue in the new lookup column as mentioned in https://github.com/SharePoint/sp-dev-docs/blob/master/docs/declarative-customization/column-formatting.md

The result is just showing ":". What do I have to do to make it work?

Regards, Elio Fernandes

1

1 Answers

1
votes

First, you need to use @currentField.lookupValue instead of @currentField.LookupValue, the first character of lookupValue should be lowercase. And the code only works if the field in the parent list is Single line of text.

enter image description here

If the type of field in the parent list is Number, you need to change the code to this:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": {
    "operator": "+",
    "operands": [
      "=substring(toString(@currentField.lookupValue),0,1)",
      "=substring(toString(@currentField.lookupValue),2,3)",
      ":",
      "=substring(toString(@currentField.lookupValue)3,5)"
    ]
  }
}