2

I'm very much new to using JSON and I try avoid it where I can. My problem is definitely lack of knowledge.

I'm trying to change the color of column values based on their lookup fields. Originally this was easy enough with one condition. However our scope now includes 6 other conditions.

I thought I was getting somewhere but the values just return a false value regardless. Any help would be appreciated.

  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "@currentField.lookupValue",
  "style": {
    "padding": "0 4px",
    "color": "=if(@currentField.lookupValue != 'Action Complete','#168DC8',
if(@currentField.lookupValue != 'Reviewed','#168DC8',
if(@currentField.lookupValue != 'Approved','#168DC8',
if(@currentField.lookupValue != 'Escalation Complete','#168DC8',
if(@currentField.lookupValue != 'QA Checked','#168DC8',
if(@currentField.lookupValue != 'Read Only Reviewed','#168DC8','white'))))))",
 "background-color": "=if(@currentField.lookupValue != 'Action Complete','White',
if(@currentField.lookupValue != 'Reviewed','White',
if(@currentField.lookupValue != 'Approved','White',
if(@currentField.lookupValue != 'Escalation Complete','White',
if(@currentField.lookupValue != 'QA Checked','White',
if(@currentField.lookupValue != 'Read Only Reviewed','White','#168DC8'))))))",
    "font-size": "14px",
    "border-width": "2px",
    "border-style": "solid"
  }
}

1 Answer 1

3

I looks to me like you want the text to be #168DC8 and the background to be white unless the lookupValue is not one of the defined conditions, then you'd like them swapped. Try this format:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField.lookupValue",
  "style": {
    "padding": "0 4px",
    "color": "=if(@currentField.lookupValue == 'Action Complete' || @currentField.lookupValue == 'Reviewed' || @currentField.lookupValue == 'Approved' || @currentField.lookupValue == 'Escalation Complete' || @currentField.lookupValue == 'QA Checked' || @currentField.lookupValue == 'Read Only Reviewed','#168DC8','white')",
 "background-color": "=if(@currentField.lookupValue == 'Action Complete' || @currentField.lookupValue == 'Reviewed' || @currentField.lookupValue == 'Approved' || @currentField.lookupValue == 'Escalation Complete' || @currentField.lookupValue == 'QA Checked' || @currentField.lookupValue == 'Read Only Reviewed','white','#168DC8')",
    "font-size": "14px",
    "border-width": "2px",
    "border-style": "solid"
  }
}
1
  • 1
    Thank you very much. This worked perfectly
    – Kyle
    Commented Apr 17, 2020 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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