cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper II
Helper II

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

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 II
Dual Super User II

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!


@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!

 

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

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.

 

 

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"

   }

]

}

 

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
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (11,968)