Forum Discussion

Benoit DELVAUX's avatar
Benoit DELVAUX
Copper Contributor
Oct 22, 2018

Multiple-selection-enabled People field properties access for View Formatting.

Hello dears,

 

I've a list with a people field ("Owners") allowing multiple selection. There will always be at least 2 people in that field.

 

Is it somehow possible to access the properties of the people field in the context of View Formatting (RowFormatter) ?

 

I'm pretty sure its not possible to loop through the values of such array but maybe its possible to arbitrarily choose like for the 2 first elements?

 

Something like [$Owners].[0].email ?

 

Thanks for your help!

  • Benoit DELVAUX's avatar
    Benoit DELVAUX
    Copper Contributor
    Ok this does the trick:

    "txtContent": "[$Owners.title]"

    But it would have been more convenient to have an index to get a specific item in the array.
    So I could have chose the 1st and 2nd owners and display them in a list / table or something.
    • navyjax2's avatar
      navyjax2
      Copper Contributor

      Benoit DELVAUX You could possibly do something like:

      "=split(join(@currentField, '|'), '|')[0]"

      to get the first element, and change the number for the next ones.

      Using [$Owners.title] will just give you a semi-colon delimited value. To iterate over the content, you can do stuff like this:

      {
        "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
        "elmType": "div",
        "children": [
          {
            "forEach": "personIterator in @currentField",
            "elmType": "div",
            "style": {
              "width": "32px",
              "height": "32px",
              "overflow": "hidden",
              "border-radius": "50%",
              "margin":"2px"
            },
            "children": [
              {
                "elmType": "img",
                "attributes": {
                  "src": "='/_layouts/15/userphoto.aspx?size=S&accountname=' + [$personIterator.email]",
                  "title": "[$personIterator.title]"
                },
                "style": {
                  "position": "relative",
                  "top": "50%",
                  "left": "50%",
                  "width": "100%",
                  "height": "auto",
                  "margin-left": "-50%",
                  "margin-top": "-50%"
                }
              },
              {
                  "elmType": "span",
                  "txtContent": "= [$personIterator.email] + ' '"
              },
              {
                  "elmType": "a",
                  "attributes": {
                    "href": "=' mailto:' +[$personIterator.email]",
                    "target": "_blank"
                  },
                  "txtContent": "=if([$personIterator] == '','','  Email user ')"
              },
              {
                  "elmType": "img",
                  "attributes": {
                    "src": "=getUserImage([$personIterator.email], 'small')",
                    "title": "[$personIterator.title]",
                    "class": "ms-bgColor-neutralLight ms-fontColor-neutralSecondary"
                  },
                  "style": {
                    "width": "=if([$personIterator] == '','0px','25px')",
                    "height": "25px",
                    "border-radius": "50%"
                  }
              }
            ]
          }
        ]
      }

      Take note of where the forEach line is, and then there are 4 different children you can use/remove.

      Instead of using that "@currentField", you can use [$MyFieldName] too.

Resources