1

So I have this sharepoint list with a (for example) "Date" column, and I want to check if any of the rows contain certain text. For example, in the rows it will either say "The due date for homework is: ", or it will say the "The due date for test is: ". Since a date will be added on to the end, I can't just check the whole string, so I want to check if it just contains a few key words. If it contains homework, turn it green, if it contains test, turn it red. Can I do this with Json? Thanks, let me know if you need more clarification

1 Answer 1

2

You can use indexOf() and other string functions to work with strings in JSON formatting as described in this article

Here is an example to change color based on your requirement. To change background, replace color attribute with background-color

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if(indexOf(@currentField, 'homework' )>0, 'Green', if(indexOf(@currentField, 'test' )>0, 'Red', 'black'))",
    "font-size": "1.12em"    
  }
}

enter image description here

1
  • Awesome thanks, indexof is exactly what I was looking for
    – mmmmm
    Commented Feb 12, 2021 at 13:48

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.