0

I have the following column of type Hyperlink and I want its default value to include a url with the Id of the item, I tried to define the format inside the JSON but it did not work, as follow:

enter image description here

So can anyone advice how i can define a default value for a HyperLink site column to include the item ID?

2 Answers 2

0

You cannot set default value using JSON Formatting. To create a hyperlink using JSON Formatting, use below JSON:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "a",
   "txtContent": "Click to filter list view",
   "attributes": {
      "target": "_blank",
      "href": "='https://abc.sharepoint.com/lists/test/allitems.aspx?FilterField1=MasterID&FilterValue1=' + [$ID]"
   }
}
1
  • Hi @johnGu, did you try this solution? Is it working for you? Commented Sep 15, 2021 at 13:50
0

We recommend that you create a Single line of text column and then convert this column into hyperlink formatting.

Please the following steps:

1.Create a Single line of text column in the list

enter image description here

2.Format this column

enter image description here

3.On the Formati column panel, click on Advanced mode

enter image description here

4.Use the below JSON:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='https://****.sharepoint.com/sites/sitename/Lists/listname/AllItems.aspx?FilterField1=MasterID&FilterValue1='+[$ID]"
  }
}

enter image description here

enter image description here

Here is a similar case for your reference:

========================== Updated Answer ======================

If you want to display the Hyperlink's URL and Alternative text in the Display Form.

Please following steps:

1.Create the following columns in the list

  • TestID: Single line of text (TestID must be equal to ID)
  • MasterID: Single line of text
  • PrimaryName: Single line of text
  • PrimaryURL: Calculated (calculation based on other columns)

Formula:

=CONCATENATE("https://***.sharepoint.com/sites/sitename/Lists/listname/AllItems.aspx?FilterField1=MasterID&FilterValue1=",[TestID])

enter image description here

  • TestLink: Single line of text

2.Column Formatting

enter image description here

3.Paste the following code:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "[$PrimaryName]",
  "attributes": {
    "target": "_blank",
    "href": "=[$PrimaryURL]"
  }
}

enter image description here

enter image description here

4.Hide Column

enter image description here

2
  • so if i follow your step , then the actual value of the column will not include the Id... it will only work if the users access the column from the list view? if this correct? this will not work inside the display form for example?
    – John John
    Commented Sep 14, 2021 at 11:45
  • Hi john Gu. I have updated answer under initial My Answer. Hope this can help you to solve issue. Have a nice day! Commented Sep 17, 2021 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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