Forum Discussion

iparker's avatar
iparker
Copper Contributor
Apr 28, 2020

JSON choice column conditional hyperlink formatting

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"
    ]
    }
    ]
    },
    "",
    ""
    ]
    }
    }
    }


    ]
    }

Resources