SOLVED

Customise library column to be link

%3CLINGO-SUB%20id%3D%22lingo-sub-2113943%22%20slang%3D%22en-US%22%3ECustomise%20library%20column%20to%20be%20link%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2113943%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20customise%20a%20column%20in%20my%20SharePoint%20library%20to%20be%20a%20link%20but%20only%20if%20the%20value%20is%201.%26nbsp%3B%20I%20also%20want%20the%20link%20to%20reference%20a%20different%20column%20for%20the%20document%20(Name).%3CBR%20%2F%3E%3CBR%20%2F%3ESo%20far%20i%20have%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%7B%3CBR%20%2F%3E%22%24schema%22%3A%20%22%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fcolumn-formatting.schema.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fcolumn-formatting.schema.json%3C%2FA%3E%22%2C%3CBR%20%2F%3E%22elmType%22%3A%20%22a%22%2C%3CBR%20%2F%3E%22attributes%22%3A%20%7B%3CBR%20%2F%3E%22target%22%3A%20%22_blank%22%2C%3CBR%20%2F%3E%22href%22%3A%20%22%3D'%3CA%20href%3D%22https%3A%2F%2Four.sharepoint.com%2Fsites%2Ftest%2FLists%2FLog%2FAllItems.aspx%3FFilterField1%3DLinkTitleNoMenu%26amp%3BFilterValue1%3D%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Four.sharepoint.com%2Fsites%2Ftest%2FLists%2FLog%2FAllItems.aspx%3FFilterField1%3DLinkTitleNoMenu%26amp%3BFilterValue1%3D%3C%2FA%3E'%20%2B%20%40nameField%3CBR%20%2F%3E%7D%2C%3CBR%20%2F%3E%22style%22%3A%20%7B%3CBR%20%2F%3E%22border%22%3A%20%22none%22%2C%3CBR%20%2F%3E%22background-color%22%3A%20%22transparent%22%2C%3CBR%20%2F%3E%22cursor%22%3A%20%22pointer%22%3CBR%20%2F%3E%7D%2C%3CBR%20%2F%3E%22children%22%3A%20%5B%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22elmType%22%3A%20%22span%22%2C%3CBR%20%2F%3E%22attributes%22%3A%20%7B%3CBR%20%2F%3E%22iconName%22%3A%20%22View%22%2C%3CBR%20%2F%3E%22class%22%3A%20%22ms-font-l%22%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%5D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EObviously%20i%20need%20the%20right%20code%20for%20the%26nbsp%3B%40namefield%20bit%20and%20the%20code%20to%20only%20be%20a%20link%20if%20the%20value%20of%20the%20field%20is%201.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2113943%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2115249%22%20slang%3D%22en-US%22%3ERe%3A%20Customise%20library%20column%20to%20be%20link%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2115249%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F955043%22%20target%3D%22_blank%22%3E%40MonkeyManvin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20JSON%20formatting%2C%20you%20have%20to%20use%20the%26nbsp%3B%3CA%20title%3D%22internal%20name%22%20href%3D%22https%3A%2F%2Fplumsail.com%2Fdocs%2Fhelp-desk-o365%2Fv1.x%2FHow%2520To%2FFind%2520the%2520internal%2520name%2520of%2520SharePoint%2520column.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Einternal%20name%3C%2FA%3E%26nbsp%3Bof%20columns.%20Display%20name%20which%20you%20see%20in%20list%2Flist%20views%20will%20not%20work%20in%20JSON.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20more%20information%20about%20supported%20column%20types%20you%20can%20refer%3A%26nbsp%3B%3CA%20title%3D%22JSON%20Formatting%20-%20Supported%20column%20types%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fcolumn-formatting%23supported-column-types%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EJSON%20Formatting%20-%20Supported%20column%20types%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%26nbsp%3B%3CSTRONG%3EMark%20as%20Best%20Response%3C%2FSTRONG%3E%26nbsp%3B%26amp%3B%20%3CSTRONG%3ELike%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20to%20solve%20your%20issue.%20This%20will%20help%20others%20to%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20post%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3ELike%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2115244%22%20slang%3D%22en-US%22%3ERe%3A%20Customise%20library%20column%20to%20be%20link%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2115244%22%20slang%3D%22en-US%22%3EJust%20tested%20and%20i%20can%20just%20ref%20by%20%24fieldname!%20%3A)%3C%2Fimg%3E%20But%20Name%20doesnt%20work%20-%20i%20presume%20it%20has%20a%20different%20name%20under%20the%20hood%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2115240%22%20slang%3D%22en-US%22%3ERe%3A%20Customise%20library%20column%20to%20be%20link%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2115240%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373269%22%20target%3D%22_blank%22%3E%40ganeshsanap%3C%2FA%3E%26nbsp%3BThanks%20again%20-%20that's%20perfect%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20this%20mean%20you%20cant%20reference%20other%20column%20when%20configuring%20a%20column%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2114316%22%20slang%3D%22en-US%22%3ERe%3A%20Customise%20library%20column%20to%20be%20link%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2114316%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F955043%22%20target%3D%22_blank%22%3E%40MonkeyManvin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20get%20the%20File%20name%20without%20extension%20you%20can%20use%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3Esubstring(%5B%24FileLeafRef%5D%2C%200%2C%20lastIndexOf('%5B%24FileLeafRef%5D'%2C%20'.'))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%20%3CSTRONG%3EMark%20as%20Best%20Response%3C%2FSTRONG%3E%20%26amp%3B%20%3CSTRONG%3ELike%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20to%20solve%20your%20issue.%20This%20will%20help%20others%20to%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20post%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3ELike%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2114261%22%20slang%3D%22en-US%22%3ERe%3A%20Customise%20library%20column%20to%20be%20link%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2114261%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373269%22%20target%3D%22_blank%22%3E%40ganeshsanap%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOf%20course!%20Didnt%20think%20of%20it%20in%20that%20way!%3CBR%20%2F%3E%3CBR%20%2F%3EYour%20code%20is%20almost%20perfect%20-%20the%20only%20issue%20is%20that%20I%20need%20the%20Name%20of%20the%20file%20from%20SP%20not%20the%20file%20name%20with%20extention%20-%20ie%20I%20need%20%3CSTRONG%3EFileName%3C%2FSTRONG%3E%20not%20%3CSTRONG%3EFileName.docx%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2113962%22%20slang%3D%22en-US%22%3ERe%3A%20Customise%20library%20column%20to%20be%20link%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2113962%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F955043%22%20target%3D%22_blank%22%3E%40MonkeyManvin%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20get%20the%20Name%20column%20(document%20name)%20in%20JSON%20using%26nbsp%3B%3CSTRONG%3E%5B%24FileLeafRef%5D%3C%2FSTRONG%3E.%20Also%2C%20you%20can%20show%2Fhide%20the%20element%20created%20in%20JSON%20using%20%22display%22%20property%20in%20%22style%22%20attribute%20like%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%22style%22%3A%20%7B%0A%20%20%20%20%22display%22%3A%20%22%3Dif(%40currentField%20%3D%3D%201%20%2C%20'none'%20%2C%20'block')%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20don't%20know%20all%20your%20requirements.%20But%2C%20as%20per%20my%20understanding%20by%20reading%20your%20question%20I%20have%20created%20below%20JSON%20code%20which%20might%20work%20for%20your%20requirements%20or%20you%20can%20modify%20accordingly%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22div%22%2C%0A%20%20%22children%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22elmType%22%3A%20%22span%22%2C%0A%20%20%20%20%20%20%22txtContent%22%3A%20%22%40currentField%22%2C%0A%20%20%20%20%20%20%22style%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22display%22%3A%20%22%3Dif(%40currentField%20%3D%3D%201%20%2C%20'none'%20%2C%20'block')%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22elmType%22%3A%20%22a%22%2C%0A%20%20%20%20%20%20%22txtContent%22%3A%20%22%40currentField%22%2C%0A%20%20%20%20%20%20%22attributes%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22target%22%3A%20%22_blank%22%2C%0A%20%20%20%20%20%20%20%20%22href%22%3A%20%22%3D'https%3A%2F%2Four.sharepoint.com%2Fsites%2Ftest%2FLists%2FLog%2FAllItems.aspx%3FFilterField1%3DLinkTitleNoMenu%26amp%3BFilterVal...'%20%2B%20%5B%24FileLeafRef%5D%22%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%22style%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22border%22%3A%20%22none%22%2C%0A%20%20%20%20%20%20%20%20%22background-color%22%3A%20%22transparent%22%2C%0A%20%20%20%20%20%20%20%20%22cursor%22%3A%20%22pointer%22%2C%0A%20%20%20%20%20%20%20%20%22display%22%3A%20%22%3Dif(%40currentField%20%3D%3D%201%20%2C%20'block'%20%2C%20'none')%22%0A%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%22children%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22elmType%22%3A%20%22span%22%2C%0A%20%20%20%20%20%20%20%20%20%20%22attributes%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22iconName%22%3A%20%22View%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22class%22%3A%20%22ms-font-l%22%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BThis%20code%20checks%20the%20value%20of%20current%20field%20where%20you%20will%20add%20the%20JSON.%20If%20value%20is%201%20then%20it%20will%20show%20as%20a%20link%20else%20simple%20text.%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%26nbsp%3B%3CSTRONG%3EMark%20as%20Best%20Response%3C%2FSTRONG%3E%26nbsp%3B%26amp%3B%20%3CSTRONG%3ELike%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20to%20solve%20your%20issue.%20This%20will%20help%20others%20to%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20post%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3ELike%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi

 

I would like to customise a column in my SharePoint library to be a link but only if the value is 1.  I also want the link to reference a different column for the document (Name).

So far i have this:

 

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "a",
"attributes": {
"target": "_blank",
"href": "='https://our.sharepoint.com/sites/test/Lists/Log/AllItems.aspx?FilterField1=LinkTitleNoMenu&FilterVal...' + @nameField
},
"style": {
"border": "none",
"background-color": "transparent",
"cursor": "pointer"
},
"children": [
{
"elmType": "span",
"attributes": {
"iconName": "View",
"class": "ms-font-l"
}
}
]
}

 

Obviously i need the right code for the @namefield bit and the code to only be a link if the value of the field is 1.  

Thanks in advance

6 Replies

@MonkeyManvin 

 

You can get the Name column (document name) in JSON using [$FileLeafRef]. Also, you can show/hide the element created in JSON using "display" property in "style" attribute like:

 

 

"style": {
    "display": "=if(@currentField == 1 , 'none' , 'block')"
}

 

 

I don't know all your requirements. But, as per my understanding by reading your question I have created below JSON code which might work for your requirements or you can modify accordingly:

 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "span",
      "txtContent": "@currentField",
      "style": {
        "display": "=if(@currentField == 1 , 'none' , 'block')"
      }
    },
    {
      "elmType": "a",
      "txtContent": "@currentField",
      "attributes": {
        "target": "_blank",
        "href": "='https://our.sharepoint.com/sites/test/Lists/Log/AllItems.aspx?FilterField1=LinkTitleNoMenu&FilterVal...' + [$FileLeafRef]"
      },
      "style": {
        "border": "none",
        "background-color": "transparent",
        "cursor": "pointer",
        "display": "=if(@currentField == 1 , 'block' , 'none')"
      },
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "iconName": "View",
            "class": "ms-font-l"
          }
        }
      ]
    }
  ]
}

 

 

 This code checks the value of current field where you will add the JSON. If value is 1 then it will show as a link else simple text.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@ganeshsanap 

Of course! Didnt think of it in that way!

Your code is almost perfect - the only issue is that I need the Name of the file from SP not the file name with extention - ie I need FileName not FileName.docx

Best Response confirmed by MonkeyManvin (Occasional Contributor)
Solution

@MonkeyManvin 

 

To get the File name without extension you can use:

 

substring([$FileLeafRef], 0, lastIndexOf('[$FileLeafRef]', '.'))

 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@ganeshsanap Thanks again - that's perfect

 

Does this mean you cant reference other column when configuring a column?

Just tested and i can just ref by $fieldname! :) But Name doesnt work - i presume it has a different name under the hood?

@MonkeyManvin 

 

In JSON formatting, you have to use the internal name of columns. Display name which you see in list/list views will not work in JSON.

 

For more information about supported column types you can refer: JSON Formatting - Supported column types 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.