formatting the column by JSON when reference to a choice field

Tuncel Biyikli 40 Reputation points
2024-08-14T08:31:31+00:00

Hi, ich have a problem! The conditional formatting should reference a choice field. If the cell is empty ("") and the column 'Equipmenttyp' has the value 'Example Device', the cell should be red. I tried also with "lookupvalue" and "value", but is not working :

{

"elmType": "div",

"style": {

Copy

"background-color": "=if(and([$Equipmenttyp] == 'Example Device', @currentField == ''), '#FFC7CE', '')"

},

"children": [

Copy

{

  "elmType": "span",

  "txtContent": "@currentField"

}

]

}

Microsoft 365 and Office SharePoint Development
0 comments No comments
{count} votes

Accepted answer
  1. Xyza Xue_MSFT 30,176 Reputation points Microsoft External Staff
    2024-08-16T01:43:13.9233333+00:00

    Hi @Tuncel Biyikli ,

    Using the following json formatting code:

    {
     "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "style": {
    "padding-left": "14px",
    "background-color": "=if(@currentField == '' &&(indexOf([$Equipmenttyp], 'Apparat') != -1), 'red', '')",
    "color": "=if(@currentField == '' &&(indexOf([$Equipmenttyp], 'Apparat') != -1), 'red', '')"
     }
    }
    
    

    User's image


    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.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Xyza Xue_MSFT 30,176 Reputation points Microsoft External Staff
    2024-08-15T02:24:39.4366667+00:00

    Hi @Tuncel Biyikli ,

    1.You should use view formatting to customize SharePoint List. Because you're referencing other columns.

    Using the following json code , when the choice column is empty (“”) and the value of the “Equipmenttyp” column is “Example Device”, the entire row will be displayed in red.

    {
     "$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
    "additionalRowClass": "=if([$choice]=='' && [$Equipmenttyp] == 'Example Device' ,'ms-bgColor-red ms-fontColor-black', '')"
    }
    

    User's image

    2.You can format choice column so that when choice column is empty (“”) and the value of the “Equipmenttyp” column is “Example Device”, the cell should be red.

    User's image


    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.


  2. Xyza Xue_MSFT 30,176 Reputation points Microsoft External Staff
    2024-08-15T08:01:58.4466667+00:00

    Hi @Tuncel Biyikli ,

    Using the following json formatting code:

    {
     "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "@currentField",
    "style": {
    "padding-left": "14px",
    "background-color": "=if(@currentField == 'Apparat' && [$Example]=='', 'red', '')",
    "color": "=if(@currentField == 'Apparat' && [$Example]=='', 'white', '')"
     }
    }
    

    Output:

    User's image


    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.


  3. Tuncel Biyikli 40 Reputation points
    2024-08-22T05:47:47.42+00:00

    Hello, thank you for your support. It's working now. The reason was the internal name of the column.


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.