Creating a custom column format in List

Gannon, James DDS St. Paul 0 Reputation points
2023-08-24T15:05:32.08+00:00

I am trying to create a custom format for a SharePoint list column that includes leading zeros in a number format. For example, I have employee numbers that are formatted as 0012, 0123, 0235, etc. and they are only ever 4 digits.

As seen here, the first few should display: 0146, 0001, 0002, (blank), 0006, and so on.

User's image

When the numbers are entered with the zeros, they are automatically removed. I want the leading 0's to stay. Any help appreciated! Just got started being our SharePoint Admin from scratch. I've used the custom column formatting before, so I know where to add that but the code is not working as I want it to.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,428 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 51,271 Reputation points Microsoft External Staff
    2023-08-25T02:16:34.2666667+00:00

    Click the number column -> Column settings -> Format this column -> Advanced mode -> Use following codes.

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

    Result:

    enter image description here


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.