0

My style is accepted but it overrides the ATTRIBUTES: Class.

How would you suggest I take advantage of incorporating the if(indexOf(@currentField inside the STYLE - which will allow me to do a wildcard?

What I need to look in fields of my SharePoint list that contain either a - or / which says its a date and change the color of that text.

Here is my code - the STYLE overrrides the ATTRIBUTES:

    {
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "debugMode": true,
  "txtContent": "@currentField",
  "style": {
    "font-weight": "bold",
    "background-color": "blue",
    "padding": "4px",
    "color": "=if(@currentField == 'NY', '#D2B48C', if(@currentField == 'MLK' , '#D2B48C',if(@currentField == 'PRES', '#D2B48C',if(@currentField == 'MEM', '#D2B48C',if(@currentField == 'INDEP', '#D2B48C',if(@currentField == 'LABOR', '#D2B48C',if(@currentField == 'TURKEY', '#D2B48C',if(@currentField == 'CHRIS', '#D2B48C',if(@currentField == 'Tan = Holiday in Time Period', '#D2B48C',if(@currentField == 'Anthony', 'red', if(@currentField == 'Hugh' , 'red',if(@currentField == 'John', 'red',if(@currentField == 'Lan', 'red',if(@currentField == 'Dan', 'red',if(@currentField == 'Jeremy', 'red',if(@currentField == 'Cory', 'red',if(@currentField == 'Mark', '#FFFF00',if(@currentField == 'Angelo', '#FFFF00',if(@currentField == 'Robert', '#FFFF00', 'black')))))))))))))))))))"
  },

  "attributes": {
    "class": "=if(indexOf(@currentField,'-') != -1 || indexOf(@currentField,'/') != -1, 'ms-fontColor-redDark','' )"
  }
}
0

This is by design, style always will override css class's attributes. If you need to check - and / condition along with comparing value of current field, you have to do it in single expression in your color attribute within style. Please check below if it works. Remove attributes node and just keep style.

AssignColorCodeRed - replace below with actual color code.

"color": "=if(indexOf(@currentField,'-') != -1,'<AssignColorCodeRed>',if(indexOf(@currentField,'/') != -1,'<AssignColorCodeRed>', if(@currentField == 'NY', '#D2B48C', if(@currentField == 'MLK' , '#D2B48C',if(@currentField == 'PRES', '#D2B48C',if(@currentField == 'MEM', '#D2B48C',if(@currentField == 'INDEP', '#D2B48C',if(@currentField == 'LABOR', '#D2B48C',if(@currentField == 'TURKEY', '#D2B48C',if(@currentField == 'CHRIS', '#D2B48C',if(@currentField == 'Tan = Holiday in Time Period', '#D2B48C',if(@currentField == 'Anthony', 'red', if(@currentField == 'Hugh' , 'red',if(@currentField == 'John', 'red',if(@currentField == 'Lan', 'red',if(@currentField == 'Dan', 'red',if(@currentField == 'Jeremy', 'red',if(@currentField == 'Cory', 'red',if(@currentField == 'Mark', '#FFFF00',if(@currentField == 'Angelo', '#FFFF00',if(@currentField == 'Robert', '#FFFF00', 'black')))))))))))))))))))))"

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.