Forum Discussion
json conditional footer with links
I'm attempting a json script to show one of three options (text, text w/hyperlink, text w/hyperlink) based on an if formula using columns and response options. Extremely new to json and not sure if it's even possible.
{
"elmType": "div",
"style":{
"display": "flex",
"flex-direction": "column",
"justify-content": "flex-start",
"align-items": "flex-start"
},
"children": [
{
"elmType": "a",
"txtContent": "=if(([$Status] == 'Approved' && [$Column1] == 'House' || [$Column1] == 'Car' || [$Column2] == 'House' || [$Column2] == 'Car'), ' The request has been approved. ', ''),
"attributes": {
"target": "_blank",
"class": "ms-fontColor-green ms-fontWeight-bold ms-fontSize-16"
}
},
{
"elmType": "a",
"txtContent": “=if(([$Status] == 'Approved' && [$Column1] == 'Condo' || [$Column1] == 'Horse' || [$Column2] == 'Condo' || [$Column2] == 'Horse') , ' The request has been approved. Right-click on this link to open the Form 1. Complete the form and upload in this section ', '')",
"attributes": {
"target": "_blank",
"class": "ms-fontColor-green ms-fontWeight-bold ms-fontSize-16",
"href": "https://dummylink1.com"
}
},
{
"elmType": "a",
"txtContent": "=if(([$Status] == 'Approved' && [$Column3] == 'Condo' || [$Column3] == 'Horse'), ' The request has been approved. Right-click on this link to open the Form 2. Complete the form and upload in this section ', '')",
"attributes": {
"target": "_blank",
"class": "ms-fontColor-green ms-fontWeight-bold ms-fontSize-16",
"href": "https://dummylink2.com"
}
}
}
]
}
- LeonPavesicSilver Contributor
Hi Deleted,
if I understood your question right, you want to display one of three options (text, text with a hyperlink, or text with a different hyperlink) conditionally in a JSON script. This could be done in this way:
{ "elmType": "div", "style": { "display": "=if([$Status] == 'Approved' && ([$Column1] == 'House' || [$Column1] == 'Car' || [$Column2] == 'House' || [$Column2] == 'Car'), '', 'none')" }, "children": [ { "elmType": "a", "txtContent": "The request has been approved.", "attributes": { "target": "_blank", "class": "ms-fontColor-green ms-fontWeight-bold ms-fontSize-16" } } ] }, { "elmType": "div", "style": { "display": "=if([$Status] == 'Approved' && ([$Column1] == 'Condo' || [$Column1] == 'Horse' || [$Column2] == 'Condo' || [$Column2] == 'Horse'), '', 'none')" }, "children": [ { "elmType": "a", "txtContent": "The request has been approved. Right-click on this link to open the Form 1. Complete the form and upload in this section", "attributes": { "target": "_blank", "class": "ms-fontColor-green ms-fontWeight-bold ms-fontSize-16", "href": "https://dummylink1.com" } } ] }, { "elmType": "div", "style": { "display": "=if([$Status] == 'Approved' && ([$Column3] == 'Condo' || [$Column3] == 'Horse'), '', 'none')" }, "children": [ { "elmType": "a", "txtContent": "The request has been approved. Right-click on this link to open the Form 2. Complete the form and upload in this section", "attributes": { "target": "_blank", "class": "ms-fontColor-green ms-fontWeight-bold ms-fontSize-16", "href": "https://dummylink2.com" } } ] }
- you can use the `if` function to conditionally set the `display` property of each `div` element.
- Depending on the conditions you specified involving `Status`, `Column1`, `Column2`, and `Column3`, one of the three `div` elements will be displayed, while the others should be hidden (`display: 'none'`).
- Each `div` element contains an `a` element with the appropriate text content and hyperlink based on the condition that should be met.Before testing the script check the following:
Data Fields: Make sure that the field names like $Status, $Column1, $Column2, and $Column3 exist and contain the expected values in your SharePoint list. If the field names are different or the data is not as expected, the conditions may not evaluate correctly.
SharePoint Column Formatting: Ensure that you are applying this JSON script correctly as column formatting in your SharePoint list. The JSON structure you provided should be used as a column format for a SharePoint column.
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.
Kindest regards,
Leon Pavesic
- Deleted
- Rob_ElliottBronze ContributorHave you ever answered a question that wasn't copied from AI?
- LeonPavesicSilver Contributor
Greetings Sir Rob_Elliott,
Well, it sounds our fellow forum member is worried that AI is taking over the world! But hey, let's address this with a dash of humor and a sprinkle of wit:
Oh, you've caught me Sherlock! Hello, my name is Leon and actually have a Faculty degree in Information Technology, just a few Microsoft Certifications, I have finished a formal Music school for piano with beeing only 14 years old (also with AI), I was avarege football player (AI helped me there also) and even my 2 kids are raised and my dog and my daughters hamster are trained and feeded just by AI. AI cooks food for my family. Perhaps, I am not human, I am AI genereted bot.
Now, I'm just waiting for AI to write my autobiography – 'The AI-ssisted Life: From Bytes to Bright Ideas'!But in all seriousness, have no fear, AI is here to assist, not replace. It's like having a super-smart sidekick that helps me provide answers faster and more accurately. Just think of it as Iron Man's Jarvis or Batman's Alfred, but for IT questions. 😄
Now, about that error we encountered in this particular case, don't worry! We're like the Sherlock Holmes and Dr. Watson of IT problem-solving. We may stumble upon a hiccup now and then, but we always find a way to crack the case and get to the solution.
And just for your info: Of course, I can absolutely give an answer without the magical touch of AI!
It's like asking Batman if he can solve crimes without his Batmobile – I've got my IT utility belt packed with knowledge, too!Now, as for providing a solution without critiquing someone's methods, well, that's just my friendly, non-judgmental side coming out. 😇 Think of me as the tech guru who's here to help without breaking out the virtual magnifying glass. So, let's dive into the IT adventures together, AI or no AI, and make tech conundrums disappear faster than a magician's rabbit in a hat!
So, instead of analyzing and fingerpointing my ALL AI-assisted answers, let's team up and tackle the mysteries of the tech world together! Or you, the great Ambassador, are just here to stalk, fingerpoint and be the hater and be afraid of new technologies. Then I am shaking you off.
P.S. When you are replying to me for the first time it is the basic culture (or manners) to write even Hi or Hello. An as I saw in some of your posts, you can't even read the questions properly, just putting your short uniformative, arrogant answers there. (Without Hi or Hello).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.
Kindest regards,
Leon Pavesic
- DeletedMaybe if I explained it in another way using a different example:
If [Status] column = 'approved' and [Position] column = 'A' or 'B', then 'Thank you' should appear as text in the sharepoint list footer.
If [Status] column = 'approved' and [Position] column = 'C' or 'D', then 'You're welcome' should appear as text in the sharepoint list footer.
If [Status] column does not = 'approved', no text should appear regardless of what is in the position column.
All help is appreciated!!