I am trying to create a document library with multiple values in a lookup field function as hyperlinks to the respective documents. By default the lookup column navigates to a details page, this is not what I wanted. I tried the below code to represent the docs as links (but this only works if there is only 1 document).
When multiple documents are selected in the lookup column, the hyperlink is still only one link, which fails.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"txtContent": "@currentField.lookupValue",
"attributes": {
"target": "_blank",
"href": "='https://.sharepoint.com/sites/sitename/libraryname/' + @currentField.lookupValue"
}
}
My second attempt was the example below. This runs the foreach if there are multiple lookup selections, but my result is creating a result of [object Object] for the title and URL.
I am assuming I need a different operator for a lookup column.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"forEach": "choiceIterator in @currentField",
"elmType": "a",
"txtContent": "[$choiceIterator]",
"attributes": {
"target": "_blank",
"href": "='https://.sharepoint.com/sites/sitename/libraryname/' + [$choiceIterator]"
},
"style": {
"width": "80px",
"height": "15px",
"text-align": "center",
"padding": "0px",
"margin": "1px"
}
}
]
}
I would like to know how to allow a multi value lookup column to function as a hyperlink to each of the documents selected using their title as the display title (individually).
Additionally, I would like to allow for a dynamic URL which will adapt to which folder the documents are currently in (my current examples are assuming a static non-folder structure.