Sharepoint column background using indexof

Boylan, Chris 0 Reputation points
2023-10-03T11:10:56.8733333+00:00

I have a text field that I want to verify (and change background colour accordingly) against either a lookup field in the same list or alternatively directly with the other list being used as the lookup. So far I have this

The text field is in the list WFD-Training-Calendar.Title and the lookup values I want to check against are in another list 'WFD Training courses'.Title The calendar also has a lookup column called 'TrainingCrsLookup' which looks up 'WFD Training courses'.Title so there are options. So far the text in the calendar title field all goes blank and I want non matches to have a red background.

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
   "elmType": "div",
   "style": {
      "background-color": "=if(indexOf('[$Lookup trng crs title]'.Title, @currentField) == -1, 'red', '')"
   },
   "children": [
      {
         "elmType": "span",
         "txtContent": "@currentField"
      }
   ]
}

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Boylan, Chris 0 Reputation points
    2023-10-25T09:57:05.2633333+00:00

    I spoke too soon, the above suggestion does not solve the problem. The WFD-Training-Calendar.Title text is red for every title (even those that are correct) unless the lookup field of the same record has the correct title (from the other list WFD-Training-courses) as its value. I would expect the indexof to scan all possible values within the training course list.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.