1

I am completely all new to this.

I have a simple SharePoint list recording training.

What coding would I need to write in, to achieve the following:

  • blank fields - color red
  • anything else with a date in goes green.

2 Answers 2

2

For your requirements, you have to use the Column formatting in SharePoint. Follow steps given here in official documentation to open column formatting settings & add below JSON code.

You can use simple JSON like below to format your date columns:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "attributes": {
        "class": "=if(Number(@currentField) == 0, 'sp-field-severity--blocked', 'sp-field-severity--good')"
    }
}

Output:

enter image description here

See other ways to check if date column is empty at: SharePoint JSON formatting: Check if date & time column is blank/empty


Official documentation: Use column formatting to customize SharePoint

1
0

You can use column formatting to meet your needs in SharePoint Online.

Please following steps:

1.Go to the list as a site admin

2.Select the "Date and time" column >> Column settings >> Format this column

enter image description here

3.On the Format Column windows, click on "Advanced mode" link

enter image description here

4.Please use the below JSON code

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "attributes": {
    "class": "=if(Number(@currentField) == 0, 'sp-field-severity--blocked','sp-field-severity--good')"
  }
}

enter image description here

5.Click "Save"

enter image description here

1
  • Is there any difference in JSON provided in my answer & your answer? Oct 19, 2021 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.