Struggling with a bit of JSON

%3CLINGO-SUB%20id%3D%22lingo-sub-1535416%22%20slang%3D%22en-US%22%3EStruggling%20with%20a%20bit%20of%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1535416%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20using%20a%20modern%20Communications%20site%20on%20SharePoint%20Online%20(365)%3C%2FP%3E%3CP%3EI%20have%20two%20lists%3A%20ListA%20and%20ListB.%3C%2FP%3E%3CP%3EI%20want%20ListA%20to%20show%20%3CU%3Edirect%3C%2FU%3E%26nbsp%3Bclickable%20hyperlinks%20to%20the%20websites%20stored%20in%20a%20hyperlink%20column%20in%20ListB.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wanted%20ListA%20to%20have%20a%20lookup%20column%20looking%20up%20on%20an%20hyperlink%20column%20on%20ListB%2C%20but%20found%20this%20is%20not%20possible.%20(or%20is%20it%3F)%3C%2FP%3E%3CP%3ESo%20ListA%20just%20has%20a%20lookup%20on%20a%20text%20column%20in%20ListB%20and%3CSTRONG%3E%20%22Allow%20multiple%20values%22%20option%20is%20ticked%20and%20must%20be%20ticked%20for%20my%20purpose.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EAll%20I%20could%20achieve%20was%20ListA%20showing%20a%20link%20to%20the%20details%20window%20of%20the%20looked-up%20entry%20in%20listB%2C%20in%20which%20the%20hyperlinks%20are%20shown.%26nbsp%3B%20That%20unfortunately%20is%20too%20clumsy%20for%20my%20purpose.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20then%20I%20created%20an%20extra%20single%20line%20text%20column%20in%20ListB%20which%20just%20holds%20the%20url%20as%20a%20piece%20of%20text%2C%20and%20another%20lookup%20column%20in%20ListA%20which%20looks%20up%20this%20text.%3C%2FP%3E%3CP%3EThis%20gave%20me%20progress%20in%20that%20ListA%20does%20now%20show%20the%20url%20text%2C%20but%20concatinates%20with%20a%20comma%20when%20there%20are%20multiple%20urls%20brought%20through.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20then%20I%20thought%20of%20using%20some%20JSON%20on%20the%20lookup%20column%20in%20ListA%20to%20display%20these%20text%20urls%20as%20active%20hyperlinks.%3C%2FP%3E%3CP%3EI%20tried%20the%20following%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%2Fv2%2Fcolumn-formatting.schema.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%3C%2FA%3E%22%2C%3CBR%20%2F%3E%22elmType%22%3A%20%22a%22%2C%3CBR%20%2F%3E%22txtContent%22%3A%20%22%40currentField%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%20%40currentField%22%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20works%2C%20%3CSTRONG%3EBUT%26nbsp%3B%3C%2FSTRONG%3Efor%20any%20line%20with%20multiple%20values%20coming%20through%20the%20lookup%20it%20simply%20binds%20them%20together%20and%20covers%20them%20with%20a%20hyperlink%20to%20the%20url%20in%20the%20first%20value.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20where%20I%20am%20struggling.%26nbsp%3B%20I've%20tried%20many%20times%20to%20code%20a%20ForEach%20loop%20in%20the%20JSON%20but%20with%20no%20joy%2C%20I%20just%20don't%20know%20JSON%20well%20enough%20and%20am%20struggling%20to%20find%20example%20code%20that%20is%20close%20enough%20to%20my%20situation%20to%20learn%20from.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EPlease%20could%20anyone%20help%20me%20with%20my%20JSON%20to%20create%20what%20I%20need%2C%20or%20suggest%20an%20alternative%26nbsp%3Bway%20to%20approach%20this%20problem%20all%20together%3F%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1535416%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1535512%22%20slang%3D%22en-US%22%3ERe%3A%20Struggling%20with%20a%20bit%20of%20JSON%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1535512%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F423287%22%20target%3D%22_blank%22%3E%40MaryHill%3C%2FA%3E%26nbsp%3B%2C%20check%20below%20article%20if%20it%20helps%20you%20to%20loop%20your%20column%20using%20forEach%3A%3C%2FP%3E%3CP%3E%3CA%20title%3D%22Generate%20List%20Formatting%20Elements%20in%20a%20Loop%20Using%20forEach%22%20href%3D%22https%3A%2F%2Fthechriskent.com%2F2019%2F04%2F04%2Fgenerate-list-formatting-elements-in-a-loop-using-foreach%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EGenerate%20List%20Formatting%20Elements%20in%20a%20Loop%20Using%20forEach%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%20%3CSTRONG%3E%3CSTRONG%3EAccept%20as%20solution%3C%2FSTRONG%3E%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20solve%20your%20issue.%20This%20will%20help%20others%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20content%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3E%3CSTRONG%3ELike%3C%2FSTRONG%3E%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
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.