1

I am trying to create a link using JSON column formatting that helps users send an email (it's an anchor element with 'mailto'). The email parameters (the recipient and email body) need to contain certain values that come from lookup columns.

I have managed to do it using the following code:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "margin": "10px",
    "justify-content": "end"
  },
  "children": [
    {
      "elmType":"div",
      "txtContent":"@currentField"
    },
    {
      "elmType": "a",
      "attributes": {
        "target": "_blank",
        "href": {
          "operator": "+",
          "operands": [
            "mailto:",
            "[$Engenheiro_x003a_E_x002d_mail]",
            "?subject=",
            "Testing Subject",
            "&body=",
            "[$Engenheiro_x003a_Engenheiro]"
          ]
        },
        "class": "ms-bgColor-themeLighter--hover ms-fontColor-themeDarker"
      },
      "style": {
        "border-radius": "2px",
        "justify-content": "center",
        "text-decoration": "none",
        "width": "32px",
        "height": "32px",
        "display": "flex"
      },
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "iconName": "MailForward"
          },
          "style": {
            "margin-top": "auto",
            "margin-bottom": "auto",
            "font-size": "16px"
          }
        }
      ]
    }
  ]
}

The output is in the image below.

enter image description here

It works as intended when the user clicks the button rendered in the list view. However, if the user tries to click on it in the Form view, both values are shown as [object Object].

Even though the link works when activated from the list view, the ability to use this link inside the form would be really useful to the users of this list. Is there a way of working around this?

The company for which I work (in whose tenant the SharePoint site is hosted) currently does not allow the use of Power Automate or Power Apps.

2
  • What is the data type of [$Engenheiro_x003a_Engenheiro] column? is it lookup OR person or group? Aug 27, 2021 at 16:21
  • @GaneshSanap, the [$Engenheiro] column is a lookup column that points to a one-line text column. The [$Engenheiro_x003a_Engenheiro] column is and additional column derived from that one and points to a one-line text column as well. Aug 27, 2021 at 16:34

1 Answer 1

0

The lookup field object has the following properties (with example values) which you can use in JSON formatting:

{
   "lookupId": "100",
   "lookupValue": "North America",
}

So, if you are using lookup column, try using it like (example):

[$Engenheiro_x003a_Engenheiro.lookupValue]

Documentation: Use column formatting to customize SharePoint


If you are using "Person or Group" field:

The people field object has the following properties (with example values):

{
   "id": "122",
   "title": "Kalya Tucker",
   "email": "[email protected]",
   "sip": "[email protected]",
   "picture": "https://contoso.sharepoint.com/kaylat_contoso_com_MThumb.jpg?t=63576928822",
   "department":"Human Resources",
   "jobTitle":"HR Manager"
}

So, you can use it like (example):

  1. To get user title:
[$Engenheiro_x003a_Engenheiro.title]
  1. To get user email:
[$Engenheiro_x003a_Engenheiro.email]
1
  • This works if I want to include the value of the lookup column itself in my link. However, both columns in my case are "additional columns". The column [$Engenheiro] is the one that does the actual lookup in another list, but I need to inlcude the values of the columns [$Engenheiro_x003a_Engenheiro] and [$Engenheiro_x003a_E_x002d_mail] which are additional ones. Aug 27, 2021 at 19:56

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.