SharePoint list - Column-Formating mit JSON

Enrico Kreisig 26 Reputation points
2022-05-30T15:38:08.917+00:00

Hello everyone,

i have a question, I want to use the following code to format column_B red in a SharePoint list if it is more than 14 days after the date in column_A.

When I apply the code to date type columns, the code works fine. However, if a column is a lookup column that gets its date value from another table, the code no longer works. Probably I need to convert the value looked up to a date value first?

How do I do that? Can someone help?

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField.lookupValue",
"attributes": {
"class": "=if([$Spalte_A] + 1209600000 < [$Spalte_B], 'ms-fontColor-redDark ms-fontWeight-semibold', '')"
}
}

Microsoft 365 and Office SharePoint Development
{count} votes

4 answers

Sort by: Most helpful
  1. Xuyan Ding - MSFT 7,601 Reputation points
    2022-06-01T03:10:01.457+00:00

    Hi @Enrico Kreisig ,

    Change the return value of the lookup type to date, and then add 14 days through the addDays function as a comparison condition with another column.
    1.If A is a column of type lookup, the code is as follows:
    {
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "style": {
    "color": "=if(Date (@currentField) > addDays(Date([$A.lookupValue]), 14), '#ff0000', '')"
    }
    }

    2.If B is a column of lookup type, you can make corresponding conditional changes.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Enrico Kreisig 26 Reputation points
    2022-06-01T08:57:28.387+00:00

    Thanks very much!

    Unfortunately the code doesn't work.
    The formatting is applied although the condition is not met.

    207420-screenshot-2022-06-01-105418.jpg


  3. Enrico Kreisig 26 Reputation points
    2022-06-06T03:26:38.943+00:00

    Too bad I can't do it.
    But many thanks for the help.


  4. Enrico Kreisig 26 Reputation points
    2022-06-06T13:03:17.383+00:00
    0 comments No comments

Your answer

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