Forum Discussion

cassirk's avatar
cassirk
Copper Contributor
Dec 23, 2019
Solved

Add hyphen with JSON based on field length

I am trying to utilize JSON to conditionally add a hyphen to a single line text column based on the length of the data in the field.  I have validation on the same column that only allows entry of 6 ...
  • cassirk's avatar
    Jan 02, 2020

    cassirk

    figured it out myself.  I was making it way too hard.

     

     

     

     

    {
      "$schema": "<a href="https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json" target="_blank">https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json</a>",
    	"elmType": "div",
      "txtContent": "=if(@currentField.length != 0,substring(@currentField,@currentField.length-4,0) + '-' + substring(@currentField,@currentField.length-4,8),'')",
    }