JSON choice column conditional hyperlink formatting

New Contributor

Is there a way to make a Choice column have a static link only when 'To Do' is selected (the default), but not when 'Complete' is selected? And then how/where do I add the conditional div/operator span colors?

 

Help!

 

I've gotten this far, but it currently does not open in a new window, and shows 'Complete' as a 404 link.

 

 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "href": "=if(indexOf(join(@currentField,''), 'To Do') !=-1, '[static URL]','Complete')",
    "target": "_blank"
  }
}

 

 

 

 

3 Replies

@iparker Try the attached JSON. You would get an image next to the to Do Item. On clicking that image you will be redirected to the page. You can also change the background of the to-do value.. 

 

{
"elmType": "div",
"style": {
"box-sizing": "border-box",
"padding": "0 2px"
},
"attributes": {
"class": {
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toLowerCase",
"operands": [
"[$Status]"
]
},
{
"operator": "toLowerCase",
"operands": [
"To Do"
]
}
]
},
"sp-css-backgroundColor-blockingBackground50",
"sp-css-backgroundColor-neutralBackground"
]
}
},
"children": [
{
"elmType": "a",
"attributes": {
"iconName": {
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toLowerCase",
"operands": [
"[$Status]"
]
},
{
"operator": "toLowerCase",
"operands": [
"To Do"
]
}
]
},
"ArrowUpRight8",
""
]
},
"class": "sp-field-quickActions",
"target": "_blank",
"href": "https://www.google.com/"

},
"class": {
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toLowerCase",
"operands": [
"[$Status]"
]
},
{
"operator": "toLowerCase",
"operands": [
"To Do"
]
}
]
},
"",
""
]
}
},

{
"elmType": "span",
"style": {
"padding": "0 2px"
},
"txtContent": "@currentField",
"attributes": {
"class": {
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
{
"operator": "toLowerCase",
"operands": [
"[$Status]"
]
},
{
"operator": "toLowerCase",
"operands": [
"To Do"
]
}
]
},
"",
""
]
}
}
}


]
}

@Maruthi GaddeYou are a LEGEND. This is perfect and easy to edit, thank you!

The image didn't load for me... how can I reference the image?