SOLVED

Custom number format with leading letters and numbers

Copper Contributor

Hi,

 

I'm tying to create a SharePoint Online List as an incident register. I'm want to have an Incident ID column formatted to display the number like such: INC001, INC002 INC003 and so on.

I can format the number column to have the leading INC but it drops off the leading 0s. I googled some code to format the number with the leading 0s but then it drops off the INC.

"{

"elmType": "div",
"txtContent": "=padStart(toString(@currentField),3,'0')"
}"
 
How do I change the code so I can have the leading lettering (INC) and leading 0s so my number column displayed as previously described.
 
Thanks in advance
3 Replies

@Sarah82 you're nearly there, use this:

{
"elmType": "div",
"txtContent": "='INC'+padStart(toString(@currentField),3,'0')"
}
 
Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP UK (and classic 1967 Morris Traveller driver)
best response confirmed by Sarah82 (Copper Contributor)
Solution

@Sarah82,

 

Adding to answer by @Rob_Elliott:

 

If you have some rows with no value in this number column, above JSON will return value like INC000 for all rows: 

ganeshsanap_0-1699277345861.pngSo instead of it, use this JSON: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(@currentField, 'INC'+padStart(toString(@currentField),3,'0'), '')"
}

 

Output

ganeshsanap_1-1699277457458.png


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Thanks very much to both @Rob_Elliott and @ganeshsanap
Much appreciated :)
1 best response

Accepted Solutions
best response confirmed by Sarah82 (Copper Contributor)
Solution

@Sarah82,

 

Adding to answer by @Rob_Elliott:

 

If you have some rows with no value in this number column, above JSON will return value like INC000 for all rows: 

ganeshsanap_0-1699277345861.pngSo instead of it, use this JSON: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(@currentField, 'INC'+padStart(toString(@currentField),3,'0'), '')"
}

 

Output

ganeshsanap_1-1699277457458.png


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

View solution in original post