Back to column formats
Column formattingSharePoint Online

Course Registration

Demonstrates creating a button to register for a course.

Course Registration formatting preview
Sample preview · View original animation

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.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "flex-directon": "row",
    "justify-content": "left",
    "align-items": "center",
    "flex-wrap": "nowrap"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "=if(indexOf([$PeopleWhoRegistered.email], @me) == -1 && length([$PeopleWhoRegistered]) != [$NumberOfPlaces] && @now <= [$RegistrationEndDate], '','none')",
        "flex-directon": "row",
        "justify-content": "left",
        "align-items": "center",
        "flex-wrap": "wrap"
      },
      "children": [
        {
          "elmType": "button",
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "PeopleWhoRegistered": "=appendTo([$PeopleWhoRegistered], @me)"
            }
          },
          "attributes": {
            "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover",
            "title": "Register"
          },
          "style": {
            "border": "none",
            "background-color": "transparent",
            "cursor": "pointer",
            "display": "flex",
            "flex-directon": "row",
            "justify-content": "left",
            "align-items": "center",
            "flex-wrap": "wrap"
          },
          "children": [
            {
              "elmType": "span",
              "attributes": {
                "iconName": "AddTo"
              },
              "style": {
                "padding": "0px"
              }
            }
          ]
        }
      ]
    },
    {
      "elmType": "div",
      "style": {
        "display": "=if(indexOf([$PeopleWhoRegistered.email], @me) > -1 && @now <= [$RegistrationEndDate], '','none')",
        "flex-directon": "row",
        "justify-content": "left",
        "align-items": "center",
        "flex-wrap": "wrap"
      },
      "children": [
        {
          "elmType": "button",
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "PeopleWhoRegistered": "=removeFrom([$PeopleWhoRegistered], @me)"
            }
          },
          "attributes": {
            "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover",
            "title": "Unregister"
          },
          "style": {
            "border": "none",
            "background-color": "transparent",
            "cursor": "pointer",
            "display": "flex",
            "flex-directon": "row",
            "justify-content": "left",
            "align-items": "center",
            "flex-wrap": "wrap"
          },
          "children": [
            {
              "elmType": "span",
              "attributes": {
                "iconName": "Blocked12"
              },
              "style": {
                "padding": "0px"
              }
            }
          ]
        }
      ]
    },
    {
      "elmType": "div",
      "children": [
        {
          "elmType": "span",
          "txtContent": "Registered",
          "style": {
            "display": "=if([$RegistrationEndDate] > @now && indexOf([$PeopleWhoRegistered.email], @me) > -1, '','none')",
            "padding-left": "5px",
            "word-break": "keep-all"
          }
        }
      ]
    },
    {
      "elmType": "div",
      "children": [
        {
          "elmType": "span",
          "txtContent": "Course is full",
          "style": {
            "display": "=if([$RegistrationEndDate] > @now && length([$PeopleWhoRegistered]) >= [$NumberOfPlaces], '','none')",
            "padding-left": "5px",
            "word-break": "keep-all"
          }
        }
      ]
    },
    {
      "elmType": "div",
      "children": [
        {
          "elmType": "span",
          "txtContent": "Registration has ended",
          "style": {
            "display": "=if([$RegistrationEndDate] > @now, 'none','inherit')",
            "padding-left": "5px",
            "word-break": "keep-all"
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

Demonstrates creating a button to register for a course. It checks if the course is already full or if the user has already registered for the course and prevents registration when either is true.

screenshot of the sample

View requirements

Type Internal Name Additional Information
DateTime RegistrationEndDate Column for when the registration period for the course ends
DateTime CourseDate Column for when the Course is scheduled
Text Register Column to show the registration button, apply the template to this column
Number NumberOfPlaces Column for the number of available places in the course
Multi-Person PeopleWhoRegistered Column to track the number of people who already registered

Sample

Solution Author(s)
text-course-registration.json Dennis, Chris Kent

Version history

Version Date Comments
1.0 November 25, 2021 Initial release
2.0 May 10, 2022 Added unregister functionality

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.


Additional notes