Forum Discussion
Customise library column to be link
- Feb 04, 2021
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.
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.
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
- ganeshsanapFeb 04, 2021MVP
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.
- MonkeyManvinFeb 05, 2021Copper Contributor
ganeshsanap Thanks again - that's perfect
Does this mean you cant reference other column when configuring a column?
- MonkeyManvinFeb 05, 2021Copper ContributorJust tested and i can just ref by $fieldname! 🙂 But Name doesnt work - i presume it has a different name under the hood?