Forum Discussion
json conditional footer with links
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