1

In a SP2019 List, I need the [Status] column value background-color to be Amber based on two conditions:

1.) if the [Status] value changes AND

2.) if the [Modified By] email address equals one of four specific email addresses

Sample:

Status: Low, Medium, High

Modified By: [email protected], [email protected], [email protected]

Ideally, I'm looking for a jQuery solution. Thank you for your help

1
  • How are you going to be able to tell that the Status value changed? Commented Nov 22 at 20:45

1 Answer 1

1

You can try below JSON formatting for your list view. You will have to apply this on your status column and make sure to include Modified By column in your view.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "background-color": "=if(@currentField == 'Low' || @currentField == 'Medium' || @currentField == 'High', if([$Editor.email] == '[email protected]' || [$Editor.email] == '[email protected]' || [$Editor.email] == '[email protected]', '#FFBF00', ''), '')"
  }
}

JQuery solution with script editor web part:

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $("table.ms-listviewtable tr").each(function() {
      var statusColumn = $(this).find("td[aria-labelledby='Status']");
      var modifiedByColumn = $(this).find("td[aria-labelledby='Editor']");

      if (statusColumn.length > 0 && modifiedByColumn.length > 0) {
        var statusText = statusColumn.text().trim();
        var modifiedByEmail = modifiedByColumn.find("span.ms-imnSpan span a").attr("email");

        if ((statusText === "Low" || statusText === "Medium" || statusText === "High") &&
            (modifiedByEmail === "[email protected]" || 
             modifiedByEmail === "[email protected]" || 
             modifiedByEmail === "[email protected]")) {
          statusColumn.css("background-color", "#FFBF00");
        }
      }
    });
  });
</script>
3
  • Thank you Dikesh! I would like to use jQuery like that above, but I need to only color the Status field if the Editor changes, not all the time. I am using this as a suggestion feature where the Status might = Low, and then you, as my manager, change the status to Medium. The amber color will indicate to me that you, as one of the email persons, are recommending a status change.
    – ChasEpes
    Commented Nov 22 at 16:04
  • and is "Editor" the same as Modified By?
    – ChasEpes
    Commented Nov 22 at 16:04
  • 1
    Editor is the internal name of the Modified By column. And you can't apply color only when editor changes status field. This jQuery approach only works based on the data stored in the columns. If you want this to be applied only when editor changes the status then you need an event receiver on the list that identifies your condition, create one flag column in the list, update value in this column from event receiver if your condition satisfies and read that column and apply color in the cell of the list view. Commented Nov 23 at 6:31

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.