Forum Discussion

lbrown1375's avatar
lbrown1375
Copper Contributor
May 20, 2022

substring statement is not working on my column formatting

On a sharepoint list on a modern site there is a single text field with the following data :

test~substring

 

I have added the below JSON to format this column to show the text 'test' but the substring does not seem to be recognised and I only see the text from within the substring :=substring(@currentField, 0, indexof(@currentField,'~')) 

 

Can anybody please help with this behaviour 

 

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",

"elmType": "span",
"txtContent": "=substring(@currentfield, 0, indexof(@currentfield,'~'))",
}

 

2 Replies

  • RobElliott's avatar
    RobElliott
    Silver Contributor

    lbrown1375 there's an incorrect comma at the end of the txtContent line. And indexOf needs a capital O.

     

    Try this:

    {
    "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "span",
    "txtContent": "=substring(@currentField, 0, indexOf(@currentField,'~'))"
    }
     
    Rob
    Los Gallardos
    Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)
    • lbrown1375's avatar
      lbrown1375
      Copper Contributor
      Thanks Rob, I have just spotted that typo now too !

Resources