web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Column formatting usin...
Power Automate
Unanswered

Column formatting using Json

(0) ShareShare
ReportReport
Posted on by

I am trying to conditional formatting a sharepoint list column based on the following rule:

 

if column "Draft Date" is blank and column "Draft Deadline" is less than today, highlight column Draft Date,

Below is the Json code I pasted to column formatting box, which I had used before, not sure why it didn't work with the new column this time.

 

{

"$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"

   }

]

}

 

 

 

Categories:
I have the same question (0)
  • Gristy Profile Picture
    2,429 on at

    what is the locale of your site?

     

    if the date is not the USA Format i.e. mm/dd/yyyy then it doesnt work properly and microsoft have ignored fixing it.

     

    https://github.com/SharePoint/sp-dev-list-formatting/issues/92#issuecomment-468966667

  • Community Power Platform Member Profile Picture
    on at

    The dates seem to be in US format. Below is a printscreen of my Sharepoint list.

     

    Json.PNG

  • Community Power Platform Member Profile Picture
    on at

    @Gristy wrote:

    what is the locale of your site?

     

    if the date is not the USA Format i.e. mm/dd/yyyy then it doesnt work properly and microsoft have ignored fixing it.

     

    https://github.com/SharePoint/sp-dev-list-formatting/issues/92#issuecomment-468966667


     

    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.

  • Gristy Profile Picture
    2,429 on at
    Inspect the html in chrome and see what is actually being inserted for more clues
  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @Anonymous 

     

    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!
  • Community Power Platform Member Profile Picture
    on at

    I pasted the code to the column "Draft Date". I have also tested it with different browser.

    I have a similar sharepoint list under the same sharepoint site, the Json code seems to work well with that sharepoint list.

     

  • yashag2255 Profile Picture
    24,769 Super User 2024 Season 1 on at

    Hey @Anonymous 

     

    In that case, can you try this on another list to confirm the issue specific to the list only. I tried it on 2 lists one new and one old andit worked fine for both. 

     

    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!

  • Community Power Platform Member Profile Picture
    on at

    Hi,

    I tried the code with another list, the problem remains. I have checked advanced list settings, which seems to ok, but problem remains.

    I also went to the first sharepoint list, update the JSON and pasted it to another column, that doesn't work either. That make me wonder if there's something wrong with my code. Below is the code I use

     

    {
      "$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"
        }
      ]
    }

     

     

  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    I sat with an ex-programmer this morning and went through the JSON code together. The problem is caused by the fiend name, for the reason the internal name of some fields is different from the field names in sharepoint list. For example, my column header is "Draft Deadline", but the internal name is Draft_x0020_Deadline.  i have updated the JSON code with internal name, now it works again.

     

    P.S. to find internal name, click list setting, click the column, you can figure out the internal name based on the URL

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard