1

I am new to JSON. Here is what I am trying to do:

first column name -> firstname and second column name -> lastname.

Then in third column I need this to display as a downloadable link -> Randomtext/firstname/lastname.

For example https://www.sagar.sharepoint.com/firstname/lastname

I tried below code but doesn't work:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "=[$firstname] + ' ' + [$lastname]",
"attributes": {
      "target": "_blank",
      "href": "='https://www.sagar.sharepoint.com/sites/file.txt' = [$firstname] + ' ' + [$lastname]"
}
}
  • In order to make it a hyperlink you need to use a element. also there was some issue with href attribute in your code. I corrected it (check below answer). You said you want the column in https://www.sagar.sharepoint.com/firstname/lastname format. But, in your code you are doing something else. I don't understand why you are appending firstname and lastname after file name. – Ganesh Sanap May 27 at 5:37
0

You can have a try with the JSON Below

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "a",
   "txtContent": "='randomeTxt'+[$firstColumnName]+' '+[$secondColumnName]",
   "attributes": {
      "target": "_blank",
      "href": "="='https://www.sagar.sharepoint.com/sites/file.txt' + [$firstColumnName] + ' ' + [$secondColumnName]"
   }
}

As I am not quite sure about the link you actually want i simply made some assumption about it.

| improve this answer | |
  • It worked..Thank you!! :) – sk5991 May 27 at 8:07
  • @sk5991 Glad to hear that. You can mark the reply as answer so other community members will be able to find it easily. – Jerry_MSFT May 27 at 8:09
0

Try using your JSON code like below:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "=[$FirstName] + ' ' + [$LastName]",
    "attributes": {
        "target": "_blank",
        "href": "='https://www.sagar.sharepoint.com/' + [$FirstName] + '/' + [$LastName]",
        "title": "='https://www.sagar.sharepoint.com/' + [$FirstName] + '/' + [$LastName]"
    }
}

Output:

enter image description here

On click of link it open new tab with URL:

enter image description here

Also, note that you need to use internal name of your First Name and Last Name columns in JSON code.

official documentation:

Use column formatting to customize SharePoint

| improve this answer | |
  • I tried but the third column is empty, doesn't display any value. What I noticed is when I am not adding the "attributes" to JSON code, the third column displays the combined values in simple text form. But as soon as i add "attributes" nothing gets displayed. – sk5991 May 27 at 5:43
  • This will give you the hyperlink with the format you mentioned: https://www.sagar.sharepoint.com/firstname/lastname – Ganesh Sanap May 27 at 5:43
  • Have you tried replacing elmType from div to a ? – Ganesh Sanap May 27 at 5:47
  • Try using updated code and replace column names in my code with internal name of your columns. – Ganesh Sanap May 27 at 5:57
  • Thanks you so much for your help!!...the code worked perfectly with the changes :) – sk5991 May 27 at 8:06

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.