SOLVED

List Lookup Conditional Formatting

Copper Contributor

Hi All

 

I have a list that is used for daily rotas. There are several lookup columns for the different job titles (A, B, C). Where the cell is empty on a specific day (eg nobody has been identified), I want the background to be red. 

 

I assumed conditional formatting would be the best solution but when I access the column settings, none of my lookup columns display as options to assign rules against - only the date.

 

I tried JSON (novice) but only succeeded in making all of my column entries disappear!

 

Help gratefully received, an also from an education point of view, is it expected functionality that you couldn't format these lookups through normal design in SP?

 

Thanks

 

Kev

3 Replies
best response confirmed by Kev2023 (Copper Contributor)
Solution

@Kev2023 You can use JSON column formatting for your lookup column like: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField.lookupValue",
  "style": {
    "padding-left": "10px"
  },
  "attributes": {
    "class": "=if(@currentField.lookupValue == '','ms-bgColor-red', '')"
  }
}

 

Output

ganeshsanap_0-1679918819357.png


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

@ganeshsanp - thank you for this, that works perfectly. Such simple JSON when you know how.

Very much appreciated.

@Kev2023 You're welcome, glad it worked for you!


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

1 best response

Accepted Solutions
best response confirmed by Kev2023 (Copper Contributor)
Solution

@Kev2023 You can use JSON column formatting for your lookup column like: 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField.lookupValue",
  "style": {
    "padding-left": "10px"
  },
  "attributes": {
    "class": "=if(@currentField.lookupValue == '','ms-bgColor-red', '')"
  }
}

 

Output

ganeshsanap_0-1679918819357.png


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

For SharePoint/Power Platform blogs, visit: Ganesh Sanap Blogs

View solution in original post