3

Basically I need to find out the item URL to populate the href attribute of an "a" element in a JSON view format (aka rowFormatter) in SharePoint online. Is there is predefined shortcut for the item URL?

     "elmType": "a",
     "attributes": {
       "href": "[$ItemUrl]"
     },
     "txtContent": "CLICK HERE"

I made the [$ItemUrl] up, it does not work like this.

4

You could use $ID.

Sample demo:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "= @currentWeb + '/ChildB/DispForm.aspx?ID=' + [$ID]"
  }
}
2
  • It works but it doesn't new window with selected item, not the right pannel (with or without custom form).
    – VNO
    Jul 19 '19 at 12:58
  • This URL isn't working for me (404 page not found). I'm working in Sharepoint Online, and the entries I'm trying to link to are modern pages. Is there a variant of this approach that will work? Nov 4 '20 at 22:03
3

There is another option that is to just use the defaultClick action:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "defaultClick"
  },
  "attributes": {
    "class": "ms-fontColor-black ms-fontColor-themePrimary--hover",
    "title": "Open eFolder"
  },
  "style": {
    "border": "none",
    "background-color": "transparent",
    "cursor": "pointer",
    "padding-left": "0px"
  },
  "children": [
    {
      "elmType": "span",
      "txtContent": "[$Name]"
    }
  ]
}

This way you dont need to worry about url string buildup

0
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='/sites/Developer/Lists/ChildB/EditForm.aspx?ID=' + [$ID]"
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.