Back to view formats
View formattingSharePoint Online

Out of Office

This sample shows how to format a list to show upcoming employee time away from office.

Out of Office formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

View formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "hideSelection": true,
  "hideListHeader": true,
  "rowFormatter": {
    "elmType": "div",
    "style": {
      "display": "flex",
      "flex-wrap": "wrap",
      "align-items": "stretch",
      "padding": "8px",
      "margin-bottom": "25px",
      "max-width": "420px",
      "border-radius": "8px",
      "min-height": "51px",
      "box-shadow": "4px 4px 8px"
    },
    "attributes": {
      "class": "ms-bgColor-themeLighterAlt ms-fontColor-themeLighter"
    },
    "children": [
      {
        "elmType": "div",
        "style": {
          "flex-grow": "1",
          "display": "flex",
          "flex-wrap": "wrap",
          "align-items": "stretch",
          "max-width": "310px"
        },
        "children": [
          {
            "elmType": "div",
            "style": {
              "flex": "none"
            },
            "children": [
              {
                "elmType": "div",
                "children": [
                  {
                    "elmType": "img",
                    "attributes": {
                      "src": "=@currentWeb + '/_layouts/15/userphoto.aspx?size=S&accountname=' + [$Who.email]",
                      "title": "[$Who.title]"
                    },
                    "style": {
                      "border-radius": "50%",
                      "vertical-align": "middle",
                      "width": "48px",
                      "height": "48px"
                    }
                  }
                ]
              }
            ]
          },
          {
            "elmType": "div",
            "style": {
              "flex-grow": "1",
              "display": "flex",
              "flex-direction": "column",
              "flex-wrap": "nowrap",
              "align-items": "stretch",
              "max-width": "200px",
              "padding": "0px 5px"
            },
            "children": [
              {
                "elmType": "div",
                "style": {
                  "flex-grow": "1"
                },
                "children": [
                  {
                    "elmType": "span",
                    "txtContent": "[$Who.title]",
                    "style": {
                      "display": "block"
                    },
                    "attributes": {
                      "class": "ms-fontSize-l ms-fontWeight-semibold ms-fontColor-neutralPrimary"
                    }
                  },
                  {
                    "elmType": "span",
                    "txtContent": "[$Title]",
                    "style": {
                      "display": "=if([$Title] == '', 'none', 'block')"
                    },
                    "attributes": {
                      "class": "ms-fontSize-m ms-fontWeight-regular ms-fontColor-neutralSecondary"
                    }
                  }
                ]
              }
            ]
          }
        ]
      },
      {
        "elmType": "div",
        "style": {
          "display": "flex",
          "flex-direction": "column",
          "max-width": "310px",
          "min-width": "150px"
        },
        "attributes": {
          "class": "ms-fontColor-neutralSecondary"
        },
        "children": [
          {
            "elmType": "div",
            "style": {
              "flex-grow": "1"
            },
            "children": [
              {
                "elmType": "span",
                "style": {
                  "display": "=if([$Startdate] <= @now,'block','none')"
                },
                "attributes": {
                  "iconName": "GotoToday",
                  "class": "ms-fontSize-s"
                }
              },
              {
                "elmType": "span",
                "style": {
                  "display": "=if([$Startdate] != '','block','none')"
                },
                "attributes": {
                  "class": "ms-fontWeight-semibold ms-fontSize-m"
                },
                "txtContent": "=if([$Startdate] <= @now,'Out of office today', 'Upcoming out of office')"
              },
              {
                "elmType": "span",
                "style": {
                  "display": "=if([$Startdate] <= @now, 'none', 'block')",
                  "padding-left": "0px"
                },
                "txtContent": "=toDateString([$Startdate])",
                "attributes": {
                  "class": "ms-fontSize-s ms-fontWeight-regular"
                }
              }
            ]
          },
          {
            "elmType": "div",
            "style": {
              "flex": "none",
              "display": "flex",
              "flex-wrap": "nowrap"
            },
            "children": [
              {
                "elmType": "span",
                "style": {
                  "display": "=if([$Enddate] && [$Enddate] != [$Startdate], 'block', 'none')",
                  "padding-left": "0px"
                },
                "txtContent": "='until '+toDateString([$Enddate])",
                "attributes": {
                  "class": "ms-fontSize-s ms-fontWeight-regular"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}

From the contributor

How to use this sample

Summary

This sample shows how to format a list to show upcoming employee time away from office. It features the following:

  • Responsive layout through flexbox
  • Conditionally showing a today icon if the out of office overlaps the current date
  • Conditionally changing the text which shows based on if the out of office start date is the current date
  • Use of theme color classes to ensure the format displays as intended regardless of theme (light, dark, custom, etc.)

screenshot of the sample

This sample is derived from the birthdays sample.

View requirements

Type Internal Name Required
Single line of text Title Yes
Person Who Yes
Date Time Startdate Yes
Date Time Enddate No

This sample relies on having a View set up which filters to only show items where either the Start date or the End date is greater than or equal to the current date. Make sure to apply the necessary filters in your view for this to work:

View Filter

Sample

Solution Author(s)
out-of-office.json Tom Resing

Version history

Version Date Comments
1.0 May 14, 2021 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.