cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
jeanwang
Level: Powered On

conditional formatting in Json

Hi,

 

I want to add a conditional formatting code to column Kickoff Complete Date. If the column is blank and today's date is greater than [Kickoff Deadline], I would like the Kickoff Complete Date to be highlighted. I understand this need to be done by inserting a Json code in column setting. But I have no clue about Json. Can someone help please?

 

conditional formatting.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Dual Super User
Dual Super User

Re: conditional formatting in Json

Hey @jeanwang 

 

In that case, can you try to update the formatting as:
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "class": "=if([$KickoffDeadline]<=@now,if(toString(@currentField) == '','sp-field-severity--warning', ''),'')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": ""
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

6 REPLIES 6
Dual Super User
Dual Super User

Re: conditional formatting in Json

Hey @jeanwang 

 

Yes. You can do that with the column formatting in JSON on the SP List. Try using the below schema: 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "class": "=if([$KickoffDeadline]<=@now,'sp-field-severity--warning', '')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": ""
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

jeanwang
Level: Powered On

Re: conditional formatting in Json


@yashag2255 wrote:

Hey @jeanwang 

 

Yes. You can do that with the column formatting in JSON on the SP List. Try using the below schema: 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "class": "=if([$KickoffDeadline]<=@now,'sp-field-severity--warning', '')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": ""
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}

Hope this Helps!

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!


Thank you very much for the scheme. It looks like you code didn't mention the first condition that the current column, i.e., [Kickoff Complete Date] should be blank.

 

Probably it will help if I explain my need in more detail. I aim to create a project plan based on SharePoint list. Each time an activity is completed, the owner needs to fill the [complete date], if the [complete date] column is blank and the deadline data is past, I would like the blank column [complete date] to be highlighted. In this way, we know at which step the project is delayed. So in my case , the condition will be:

if current column [Kickoff Complete Date] is blank,

&

column [Kickoff Deadline] <now

highlight current column [Kickoff Complete Date]

end if

 

Can you please help with the schema?

 

Thank you!

 

Dual Super User
Dual Super User

Re: conditional formatting in Json

Hey @jeanwang 

 

In that case, can you try to update the formatting as:
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "class": "=if([$KickoffDeadline]<=@now,if(toString(@currentField) == '','sp-field-severity--warning', ''),'')"
  },
  "children": [
    {
      "elmType": "span",
      "style": {
        "display": "inline-block",
        "padding": "0 4px"
      },
      "attributes": {
        "iconName": ""
      }
    },
    {
      "elmType": "span",
      "txtContent": "@currentField"
    }
  ]
}
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

jeanwang
Level: Powered On

Re: conditional formatting in Json

Thank you  so much! It works perfectly this time. This give me a start on Json as well, I will try to learn a bit about Json myself so that I can configure the objects and operators myself in future.

jeanwang
Level: Powered On

Re: conditional formatting in Json

 

 

Hi Jashag,

You shared with me a Json script for column formatting which worked perfectly last time. However, when I tried to update the script and paste it to another column. It doesn't seem to work.

Below is my Sharepoint list and the script I pasted to column Draft Deadline.

 

Actually the Json code seem to do something strange with my sharepoint list. Instead of highlight the column in yellow as it should be, it seem to highlight the column into white or hide values being put into the column. I had input a date into the Draft Date column, but the date was invisible if the Json code was there. Date re-appeared after I removed the Json code. Do you know the reason?

 

Thanks!

 

Json.PNG

{

"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",

"elmType": "div",

"attributes": {

   "class": "=if([$DraftDeadline]<=@now,if(toString(@currentField) == '','sp-field-severity--warning', ''),'')"

},

"children": [

   {

     "elmType": "span",

     "style": {

       "display": "inline-block",

       "padding": "0 4px"

     },

     "attributes": {

       "iconName": ""

     }

   },

   {

     "elmType": "span",

     "txtContent": "@currentField"

   }

]

}

 

Dual Super User
Dual Super User

Re: conditional formatting in Json

Hey @jeanwang 

 

If you want to change the color of DraftDate column, you need to place the column formatting in the Draft Date column and not the Draft Deadline column. I carried out a test on my side and the formatting shared by you works fine.MicrosoftTeams-image (84).png

 

Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (6,521)