JSON Statement Help

%3CLINGO-SUB%20id%3D%22lingo-sub-1360164%22%20slang%3D%22en-US%22%3EJSON%20Statement%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1360164%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20JSON%20statement%20that%20I'm%20getting%20an%20error%20on.%26nbsp%3B%20Error%20is%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22eenochs-turner_0-1588686382274.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F188972i32BDDFF0C3E9F607%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22eenochs-turner_0-1588686382274.png%22%20alt%3D%22eenochs-turner_0-1588686382274.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EJSON%20Statement%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22div%22%2C%0A%20%20%22debugMode%22%3A%20true%2C%0A%20%20%22txtContent%22%3A%20%22%40currentField%22%2C%0A%20%20%22style%22%3A%20%7B%0A%20%20%20%20%22color%22%3A%20%22if%3D(%5B%24EMR_x0020_Effective_x0020_Date%5D%20%3D%3D%20'%20'%20%26amp%3B%26amp%3B%20%5B%24EMR_x0020_Effective_x0020_Date%5D%20%2B31556952000%20%26lt%3B%3D%20%40now%2C%20'%23ff0000'%2C%20'%23000000')%22%0A%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI'm%20trying%20to%20look%20at%20one%20column%20and%20if%20the%20EMR%20Effective%20Date%20is%20less%20than%20the%20date%20%2B%20a%20year%20or%20if%20the%20entry%20is%20blank%20the%20text%20will%20be%20red.%26nbsp%3B%20Error%20has%20to%20be%20in%20the%20statement%20but%20not%20sure%20where%20it%20is%20at.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1360164%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1364604%22%20slang%3D%22en-US%22%3ERe%3A%20JSON%20Statement%20Help%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1364604%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F314143%22%20target%3D%22_blank%22%3E%40eenochs-turner%3C%2FA%3E%26nbsp%3BIn%20the%20below%20code%20i%20could%20see%20two%20things%20which%20might%20need%20to%20be%20corrected%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%22color%22%3A%20%22if%3D(%5B%24EMR_x0020_Effective_x0020_Date%5D%20%3D%3D%20'%20'%20%26amp%3B%26amp%3B%20%5B%24EMR_x0020_Effective_x0020_Date%5D%20%2B31556952000%20%26lt%3B%3D%20%40now%2C%20'%23ff0000'%2C%20'%23000000')%22%3C%2FCODE%3E%3C%2FPRE%3E%3COL%3E%3CLI%3EYour%20are%20using%20%26amp%3B%26amp%3B%20operator%20instead%20of%20%7C%7C%26nbsp%3B%3C%2FLI%3E%3CLI%3EYou%20are%20trying%20to%20set%20color%20for%20a%20text%20which%20is%20blank%20which%20will%20never%20happen%3C%2FLI%3E%3C%2FOL%3E%3CP%3EIf%20you%20want%20to%20achieve%20something%20like%20this%20I%20will%20write%20something%20like%20this%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22div%22%2C%0A%20%20%22attributes%22%3A%20%7B%0A%20%20%20%20%22class%22%3A%20%22%3Dif(toString(%5B%24Date%5D)%20%3D%3D''%2C'sp-field-severity--severeWarning'%2Cif(%5B%24Date%5D%20%26lt%3B%3D%20%40now-31556952000%2C'sp-field-severity--severeWarning'%2C%20''))%22%0A%20%20%7D%2C%0A%20%20%22children%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22elmType%22%3A%20%22span%22%2C%0A%20%20%20%20%20%20%22style%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22display%22%3A%20%22inline-block%22%2C%0A%20%20%20%20%20%20%20%20%22padding%22%3A%20%220%204px%22%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22elmType%22%3A%20%22span%22%2C%0A%20%20%20%20%20%20%22txtContent%22%3A%20%22%40currentField%22%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3BHope%20this%20helps!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

I have a JSON statement that I'm getting an error on.  Error is 

eenochs-turner_0-1588686382274.png

JSON Statement 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "@currentField",
  "style": {
    "color": "if=([$EMR_x0020_Effective_x0020_Date] == ' ' && [$EMR_x0020_Effective_x0020_Date] +31556952000 <= @now, '#ff0000', '#000000')"
}
}

I'm trying to look at one column and if the EMR Effective Date is less than the date + a year or if the entry is blank the text will be red.  Error has to be in the statement but not sure where it is at.  

 

1 Reply
Highlighted

@eenochs-turner In the below code i could see two things which might need to be corrected 

 

"color": "if=([$EMR_x0020_Effective_x0020_Date] == ' ' && [$EMR_x0020_Effective_x0020_Date] +31556952000 <= @now, '#ff0000', '#000000')"
  1. Your are using && operator instead of || 
  2. You are trying to set color for a text which is blank which will never happen

If you want to achieve something like this I will write something like this:

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

 Hope this helps!