JSON Code - Course Registration

Martin, Heidi (SE GP T SP PS) 571 Reputation points
2023-12-14T13:54:12.1766667+00:00

Hello,

Is it possible to hide employees who are already registered so that they cannot be seen by others? Thank you!

User's image

This is the code:

{
  "$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"
          }
        }
      ]
    }
  ]
}
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,229 questions
{count} votes

Accepted answer
  1. Ling Zhou_MSFT 23,610 Reputation points Microsoft External Staff
    2023-12-15T09:37:18.6833333+00:00

    Hi @Martin, Heidi (SE GP T SP PS),

    Thank you for your reply.

    What I understand is that you want the registrant to see only their own registration in the "People Who Registered" column and not the registration of others. Correct me if I have misunderstood.

    If I understand you correctly, please try use this JSON to format your ""People Who Registered" column":

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "style": {
        "flex-direction": "column"
      },
      "children": [
        {
          "elmType": "div",
          "forEach": "person in @currentField",
          "children": [
            {
              "elmType": "div",
              "children": [
                {
                  "elmType": "div",
                  "style": {
                    "display": "=if(indexOf([$person.email], @me) != -1, '','none')"
                  },
                  "txtContent": "=[$person.title]"
                }
              ]
            }
          ]
        }
      ]
    }
    

    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.
    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Martin, Heidi (SE GP T SP PS) 571 Reputation points
    2023-12-15T05:46:57.4266667+00:00

    @Ling Zhou_MSFT

    Good morning,

    Ok - When I click on "Register" my name appears in "People Who Registered" - but the desire is that when I have registered, my name is no longer visible so that other collaborators cannot see who has registered.

    0 comments No comments

  2. Martin, Heidi (SE GP T SP PS) 571 Reputation points
    2023-12-15T09:43:47.7+00:00

    Thank you so much!

    0 comments No comments

  3. Martin, Heidi (SE GP T SP PS) 571 Reputation points
    2023-12-21T15:00:34.9233333+00:00

    @Ling Zhou_MSFT

    Hello, One more question, is it possible to count down the "Number Of Places" after a registration?

    If I have 5 places, it would be great if each registration is counted down.

    Example:

    Registration 1 - Places 4
    Registration 2 - Places 3

    Registration 3 - Places 2

    **
    Thank you!


  4. Martin, Heidi (SE GP T SP PS) 571 Reputation points
    2024-01-18T16:14:25.6566667+00:00

    @Ling Zhou_MSFT

    Hello,

    I have another question: When the registration is full, can you set it so that you can no longer click on the plus button? Thank you! User's image

    This is my code:

    {
      "$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": "- Registration 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"
              }
            }
          ]
        }
      ]
    }
    

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.