Struggling with a bit of JSON

Brass Contributor

I am using a modern Communications site on SharePoint Online (365)

I have two lists: ListA and ListB.

I want ListA to show direct clickable hyperlinks to the websites stored in a hyperlink column in ListB.

 

I wanted ListA to have a lookup column looking up on an hyperlink column on ListB, but found this is not possible. (or is it?)

So ListA just has a lookup on a text column in ListB and "Allow multiple values" option is ticked and must be ticked for my purpose.

All I could achieve was ListA showing a link to the details window of the looked-up entry in listB, in which the hyperlinks are shown.  That unfortunately is too clumsy for my purpose.

 

So then I created an extra single line text column in ListB which just holds the url as a piece of text, and another lookup column in ListA which looks up this text.

This gave me progress in that ListA does now show the url text, but concatinates with a comma when there are multiple urls brought through.

 

So then I thought of using some JSON on the lookup column in ListA to display these text urls as active hyperlinks.

I tried the following:

 

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

 

This works, BUT for any line with multiple values coming through the lookup it simply binds them together and covers them with a hyperlink to the url in the first value.

 

This is where I am struggling.  I've tried many times to code a ForEach loop in the JSON but with no joy, I just don't know JSON well enough and am struggling to find example code that is close enough to my situation to learn from.

 

Please could anyone help me with my JSON to create what I need, or suggest an alternative way to approach this problem all together?

1 Reply

@MaryHill , check below article if it helps you to loop your column using forEach:

Generate List Formatting Elements in a Loop Using forEach 


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