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
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"
}
}