0

enter image description here

Hi there,

I am relatively new to using SharePoint as well as JSON and as mentioned in the subject, I am having issues in trying to reference the Version column (set by the approval status).

What I hope to achieve is such that if the "version" number is the same as the "version flow" number, a conditional formatting would be set to show a green background and red if the version flow number is less than the version number.

I have hard coded the values of 13 just to see if I could get the colours to appear. Whenever I try to reference [$Version], the values in version flow would disappear. Help on the matter would be greatly appreciated!

I have attached my current code applied to th 'Version Flow' column as conditional formatting.

{
  "elmType": "div",
  "txtContent": "@currentField",
  "attributes": {},
  "style": {
    "background-color": {
      "operator": "?",
      "operands": [
        {
          "operator": ">=",
          "operands": [
            "@currentField",
            "13.0"
          ]
        },
        "#98FB98",
        {
          "operator": "?",
          "operands": [
            {
              "operator": "<",
              "operands": [
                "@currentField",
                "13.0"
              ]
            },
            "#FF6A6A",
            ""
          ]
        }
      ]
    }
  },
  "customRowAction": {},
  "children": []
}
  • Also, you are saying What I hope to achieve is such that if the "version" number is the same as the "version flow" number and you are checking the condition for greater than or equal to in your first condition. check this. – Ganesh Sanap Sep 3 at 8:58
  • Thanks for pointing this out. It's actually another issue that I have yet to resolve. Strangely when say for example, version = 15.1 and version flow = 15.1, when I set the condtion operator to "==", the condition result is false. Any idea why> = – cyw_bat Sep 4 at 1:31
  • What is the data type of Version flow field? – Ganesh Sanap Sep 4 at 2:20
  • I just found my error thanks to your question! Version flow was originally of number type. I changed it to string and now it works. – cyw_bat Sep 5 at 3:05
  • Glad to hear that it worked for you. – Ganesh Sanap Sep 5 at 3:56
0

Instead of using [$Version], use [$_UIVersionString].

So, your code should be something like below:

{
  "elmType": "div",
  "txtContent": "@currentField",
  "attributes": {},
  "style": {
    "background-color": {
      "operator": "?",
      "operands": [
        {
          "operator": ">=",
          "operands": [
            "@currentField",
            [$_UIVersionString]
          ]
        },
        "#98FB98",
        {
          "operator": "?",
          "operands": [
            {
              "operator": "<",
              "operands": [
                "@currentField",
                [$_UIVersionString]
              ]
            },
            "#FF6A6A",
            ""
          ]
        }
      ]
    }
  },
  "customRowAction": {},
  "children": []
}

Note: Version is a Single line of text field.

  • Try above code and let me know if it works or not. – Ganesh Sanap Sep 3 at 8:54
  • Works like a charm! Thank you so much Ganesh. – cyw_bat Sep 4 at 0:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.