JSON Countdown Stop at 0 days - json

I have found a great count down that I'm am using in SharePoint to count down to a date. I have a calculated column that has today + number of days for a task to be complete. at the moment the count down keeps going and show - days and I would like it to stop at 0 days. I don't know if this is possible? any help would be great.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=floor((Number(#currentField)-Number(Date((getMonth(#now)+1)+'.'+getDate(#now)+'.'+getYear(#now))))/(60*60*24*1000))+' day(s) remaining'"
}

You want to display "0 day(s) remaining" when the countdown is less than 0 days, right?
Use this Json codeļ¼š
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(#currentField>#now,(floor((Number(#currentField)-Number(Date((getMonth(#now)+1)+'.'+getDate(#now)+'.'+getYear(#now))))/(60*60*24*1000))+' day(s) remaining'),'0 day(s) remaining')"
}

Related

Trying to combine two columns using JSON on Sharepoint site

I am new to using JSON, I have been trying to develop JSON code to combine the results from two columns to set the color in a third column, I have been trying for two weeks now with no luck. This code is in a column called Mock, I am trying to read a column called Process which currently has the word Mock in it. I have a second column called Status which has the word Complete in it. Currently the cell I am interested in has the date 2/2/2022 in it. I cannot see any date in the cell.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-
formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"background-color": "=if(Number(#currentField)==0,if($Process == 'Mock' && if($Status ==
'Complete', '#0000FF','white'))"
}
}
Please use the below JSON formatting:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"background-color": "=if(Number(#currentField) == 0,'',if(([$Process] == 'Mock' && [$Status] == 'Complete'),'#0000FF','#FFFFFF'))"
}
}

SharePoint Online - Lookup Display multiples values in Form

I'm trying to show multiple columns in one line of data in my form via a dropdown Menu.
Right now, it's just showing the Title and I can change it. I want to format it to :
ID + " - " + Title
I saw the Display Column Formatting in JSON at the EDIT Column in SPO but I don't know if thats what I'm looking for.
Thanks !
Try the below JSON code.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": {
"operator": "+",
"operands": [
"[$ID]",
"-",
"[$Title]"
]
}
}

How do I use JOSN code to turn a Request Date text to RED when the request is greater that 5 days in a SharePoint list

I have the following in my column format, however the text does not turn red
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-
formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": "=if([$Request_x0020_Date] >= #now + 432000000, '#ff0000', '')"
}
}
I have data in my list form 7/15, which is greater than 5 days and items from today. If I change the less than, greater than symbols I can get the text to turn red, but it turns it all red.
Please help!
As per my test, below JSON code works well on my end.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-
formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": "=if([$RequestDate] >= #now + 432000000, '#ff0000', '')"
}
}
Pay attention to column variation $Request_x0020_Date in your code, you have to use the internal name of the column after "$". You can get the internal name of the column via List settings -> Columns section -> Click the column name to edit. You can find the internal name from the URL. For example, "RequestDate" after "Field=" is the internal name of my column "Request Date".

SharePoint Lookup Column - Number Format to remove commas

I have a lookup column in SharePoint 2019 that is looking back to a number field from a custom list.
I used the following JSON to format the lookup column to display the number without the hyperlink:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField.lookupValue"
}
I want to also remove the thousands commas to display the numbers from 1,234 to just 1234
Any suggestions on how this can be done simply? Seems odd there is no simple option to change the view format. (P.S. my JSON coding ability isn't great!)
There are a couple of ways to achieve this, some are a bit hack-ish but work:
if you are using Modern List Experience you can simply achieve this by applying following conditional formatting JSON to the number column in your lookup list:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(#currentField > 0,'', '')"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block"
}
},
{
"elmType": "span",
"txtContent": "#currentField"
}
]
}
For Classic Experience a workaround could be to keep the data type of your number column as single line of text in your lookup list and apply the following formula in column validation section:
=ISNUMBER([text-column-name]+0)
hope this helps.
You could try the below json code:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": {
"operator": "+",
"operands": [
"=substring(#currentField.lookupValue,0,1)",
"=substring(#currentField.lookupValue,2,6)"
]
}
}
Change txtContent to =replace(#currentField.lookupValue, ',', ''):
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=replace(#currentField.lookupValue, ',', '')"
}

Formatting Sharepoint List Date or Choice Column with JSON

I am very new to all this. I dont really know what most of these codes are, but with a little searching and trial an error I achieve my goals by changing bits and pieces. My current goal is to format a fields background color depending on the value of that field.
I found a very nice post on the subject. The problem is I need to combine a couple examples and I am having a problem. Here is the post.
https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting.
I have a date field called "Proposal Due Date". When the date is past, I want the BG one color. When the date is approaching (5 working days out) I want the BG another.
Below are the 2 examples I found and edited. I can only do one or the other. I need them both in the same format column box.
I can do the first part easy. It makes the BG a redish color if the date is past... Except it included todays date.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"debugMode": true,
"txtContent": "#currentField",
"style": {
"background-color": "=if([$Proposal_x0020_Due_x0020_Date] < #now, '#FAAAAA', '')"
}
}
The second part is a bit tricky for me. I dont know how to make this check 5 working days ahead instead of just 5 days. I also dont know how to prevent it from including days past.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "#currentField",
"style": {
"background-color": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
"[$Proposal_x0020_Due_x0020_Date]",
{
"operator": "+",
"operands": [
"#now",
432000000
]
}
]
},
"#FCFC00",
""
]
}
}
}