Apr 10 2020 08:28 AM
I am trying to format a column to change color if TODAY is greater than the date entered, plus 365 days. It's basically to show a color for expiration of date entered. Below is what I was trying to figure out, but this doesn't work. Thanks!
{
"schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"additionalRowClass": "=if(@now()+365 > [$COLUMN_x0020_NAME], 'sp-field-severity--severeWarning', '')"
}
Apr 13 2020 06:37 AM - edited Apr 13 2020 06:38 AM
Solution
Is this what you are looking for?
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "=if([$DateColumn] >= @now + 365, 'ms-fontColor-themePrimary ms-fontWeight-bold', '')"
}
}
I hope this helps.
Norm
Apr 13 2020 12:23 PM
Apr 13 2020 12:31 PM
Apr 13 2020 03:35 PM
@Norman Young Taking another look at that, it still isn't working correctly. I'm trying to color it if it is more than 365 days old from today, i.e. more than a year old.
I've tried to move the formula around, but I still can't get it to do that. Not sure what's going on LOL!
Apr 13 2020 04:20 PM
Apr 14 2020 05:05 AM - edited Apr 14 2020 06:12 AM
@Norman Young The code works, but your example date is in the future. What I am trying to do is color the text when the date is past one year old. The attached example (screenshot) is your code with a date that is over 365 days in the past. The text is unchanged. It seems simple enough, but I've struggled with it for a couple days before you took a crack at it. Makes me crazy!
If you move the items around, a date that is less than a year old still shows as colored and bold. It's only supposed to do that if it's more than a year old.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "=if(@now >= [$Expiration] + 365, 'ms-fontColor-themePrimary ms-fontWeight-bold', '')"
}
}
Apr 14 2020 06:13 AM
@Norman Young The code works, but your example date is in the future. What I am trying to do is color the text when the date is past one year old. The attached example (screenshot) is your code with a date that is over 365 days in the past. The text is unchanged. It seems simple enough, but I've struggled with it for a couple days before you took a crack at it. Makes me crazy!
If you move the items around, a date that is less than a year old still shows as colored and bold. It's only supposed to do that if it's more than a year old.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "=if(@now >= [$Expiration] + 365, 'ms-fontColor-themePrimary ms-fontWeight-bold', '')"
}
}
Apr 14 2020 12:48 PM
Hi @alandarr,
Try this:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "=if(floor((Number(@now)-Number([$DateColumn]))/(1000*60*60*24*365)) > 0, 'ms-fontColor-themePrimary ms-fontWeight-bold', '')"
}
}
Apr 15 2020 07:12 AM - edited Apr 15 2020 07:14 AM
@Norman Young That works! I knew it had to be more complicated than what I was trying. Can I buy you a cup of coffee? Thank you so very much with helping. I'm new to Sharepoint and feel a bit overwhelmed. Thanks again!
Now, if I can figure out how to mark this answer as correct instead of the other one...
Apr 15 2020 07:28 AM
I appreciate the coffee offer @alandarr but it is unnecessary. I'm glad things worked out. Reach out again if you get stuck.
Norm
Apr 13 2020 06:37 AM - edited Apr 13 2020 06:38 AM
Solution
Is this what you are looking for?
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "=if([$DateColumn] >= @now + 365, 'ms-fontColor-themePrimary ms-fontWeight-bold', '')"
}
}
I hope this helps.
Norm