Forum Discussion
Json conditional formatting based on a multi-lookup projected field
I have an issue with formating a set of Multi-lookup fields with projected fields in my sharepoint list.
What I am looking to do is format the PrimaryLookup so that it checks the animal type projected field, and then formats the Primarylookup column accordingly.
In the example below what I want to happen is for text colour for Mr. Squiggles and Godzilla Jr. to change to red because they are dogs, but other animals names would be green.
I am currently able to format the projected field using a forEach to split the cell into an array and format each part of the projected field directly, but cannot figure out how to instead use the information in the projected field to correctly format thePrimaryLookup.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"display": "flex",
"flex-direction": "column",
"align-items": "flex-start",
"padding": "11px 0",
"min-height": "0"
},
"children": [
{
"elmType": "div",
"children": [
{
"forEach": "itemIterator in split([$PrimaryLookup_x0020_lookup_x003a__x0],';')",
"elmType": "div",
"txtContent": "[$itemIterator]",
"style": {
"padding-bottom": "1px",
"color": "=if(indexOf([$itemIterator], 'Dog' )!= -1, 'Red', 'Green')"
}
}
]
}
]
1 Reply
- EtheianoBrass Contributor
Use the switch function in SharePoint list JSON formatting to determine multiple lookup field values. Here is a sample code snippet:
json
{
“elmType”: “div”,
“style”: {
“color”: “=switch([$MultiLookup], ‘Value1’, ‘green’, ‘Value2’, ‘red’, ‘black’)”
}
}