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

Column formatting using Json

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"

   }

]

}

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jeanwang
Level: Powered On

Re: Column formatting using Json

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

View solution in original post

9 REPLIES 9
Super User
Super User

Re: Column formatting using Json

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

jeanwang
Level: Powered On

Re: Column formatting using Json

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

 

Json.PNG

jeanwang
Level: Powered On

Re: Column formatting using Json


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

Super User
Super User

Re: Column formatting using Json

Inspect the html in chrome and see what is actually being inserted for more clues
Dual Super User
Dual Super User

Re: Column formatting using 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!
jeanwang
Level: Powered On

Re: Column formatting using Json

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.

 

Dual Super User
Dual Super User

Re: Column formatting using Json

Hey @jeanwang 

 

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!

jeanwang
Level: Powered On

Re: Column formatting using Json

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

 

 

jeanwang
Level: Powered On

Re: Column formatting using Json

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

View solution in original post

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 (3,787)