Forum Discussion
cassirk
Dec 23, 2019Copper Contributor
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 ...
- Jan 02, 2020
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),'')", }
cassirk
Jan 02, 2020Copper Contributor
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),'')",
}