Sharepoint - Formatting a Column (JSON)

sl23 21 Reputation points
2021-10-19T08:04:00.417+00:00

I have a sharepoint list, I want the field to go green when training has been completed and for the field to go red when it is empty. Could some please help?

141684-image.png

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

Answer accepted by question author
  1. Allen Xu_MSFT 13,896 Reputation points
    2021-10-20T02:00:13.45+00:00

    Hi @sl23 ,

    To format a column based on its field value, please take a reference to the following JSON example:

    {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
      "elmType": "div",  
      "txtContent": "@currentField",  
      "style": {  
        "background-color": "=if((@currentField == 'Completed', '#00ff00', if(@currentField == '', '#ff0000', '#DDA0DD')"  
        }  
    }  
    

    141878-image.png

    If you want format the color of another column based on the "training" column, please take a reference to the below JSON.

    {  
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
      "elmType": "div",  
      "txtContent": "@currentField",  
      "style": {  
        "background-color": "=if(([$training] == 'Completed', '#00ff00', if([$training] == '', '#ff0000', '#DDA0DD')"  
      }  
    }  
    

    141829-image.png

    ----------

    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.


0 additional answers

Sort by: Most helpful

Your answer

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