1

I am trying to archive the following within a document library modern experience on SharePoint Online:

  • All minor version (everything .1-9) the background should have the color red or similar

  • All Major versions (1.0, 2.0, 3.0 etc.) should have the background color green or similar.

It needs to be done via JSON and via the "format this column" in SharePoint Online.

Is there a way to create an "IF-Clause" checking only the last digit? If yes, I could easily identify, due to the fact, that all major version are a "0" at the end. Maybe something like RIGHT[@currentField]? If so, how do I implement that into an IF-Clause?

Current state of my pretty poor JSON:

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
   "elmType": "div",
   "attributes": {
     "class": "=if(@currentField <= '0.9','sp-field-severity--warning', '')"
   },
   "children": [
     {
       "elmType": "span",
       "style": {
         "display": "inline-block",
         "padding": "0 4px"
       },
       "attributes": {
         "iconName": "=if(@currentField <= '0.9','Error', '')"
       }
     },
     {
       "elmType": "span",
       "txtContent": "@currentField"
     }
   ]
 }

2 Answers 2

2

We can use the JSON formatting below to achieve it.

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
   "elmType": "div",
   "style": {
    "background-color": "=if(indexOf(@currentField, '.0')!=-1, 'green', 'red')",
    "color":"white" 
   },
   "children": [
     {
       "elmType": "span",
       "style": {
            "margin-top":"11px"
       },
       "txtContent": "@currentField"
     }
   ]
 }

enter image description here

2
  • Thank you so much! I'm glad to be back here in this community. I know, why I asked my question in this forum! Could you maybe also write a sentence or two, what how it actually works and what the IF-Clause means? Commented Mar 20, 2019 at 7:16
  • 1
    I suggest you read the official document: docs.microsoft.com/en-us/sharepoint/dev/… Commented Mar 20, 2019 at 9:07
1

slightly updated version making use of the supported CSS styles:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "class": "=if(indexOf(@currentField, '.0')!=-1,'sp-field-severity--good', 'sp-field-severity--warning')"
  },
  "children": [
    {
      "elmType": "span",
      "txtContent": "=if(indexOf(@currentField, '.0')!=-1, '@currentField', @currentField + ' - Publish me!')"
    }
  ]
}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.