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

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

  • 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? – Patrick Mar 20 at 7:16
  • 1
    I suggest you read the official document: docs.microsoft.com/en-us/sharepoint/dev/… – LZ_MSFT Mar 20 at 9:07

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.