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'))"
}
}
Related
Been working on some sample code to format a list column B based on value of list column A.
I have 2 lists:
List A - This list are the main list for data entry. Columns are Item, Region and Country.
List B - This list contains 2 columns; Region and Country.
What I want to do is, based on user selection, only display Country corresponding to the selection Region. All Countries/Regions are maintained in List B.
So far I've tried:
{
"$schema": "https://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"elmType": "div",
"style": {
"display": "inline-block",
"padding": "10px 0 10px 0",
"min-height": "auto"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 10px 0 0"
},
"attributes": {
"iconName": "Folder"
}
},
{
"elmType": "a",
"txtContent": "Show Countries",
"attributes": {
"target": "_top",
"href": {
"operator": "+",
"operands": [
"https://xxxxxxxxxxxx/AllItems.aspx?ID=",
"#currentField.lookupValue",
"[$Title]",
"&FilterType1=Lookup"
]
}
}
}
]
}
This obviously is not the correct solution, but being very new to JSON this is the best I could do by referencing msdn docs. The link works properly, although it's not needed for the final solution. Basically, I only want the user to see Country based on Region selection. I'm therefore missing the result as to display the lookup value rather than "Show countries".
Any help or pointers towards further help/documentation are greatly appriciated.
According to my research, the JSON formatting does not support create cascading dropdown on SharePoint Online.
You can use SP service (JS) to create cascading drop-down list.
Reference:
How to create Cascading Drop Down list in SharePoint
Online/2016/2013/2010 - Using SP Services (JS )
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".
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, ',', '')"
}
I have the following code given by Michael Han that is working just fine. It formats a number like '2030' to be '20:30'
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": {
"operator": "+",
"operands": [
"=substring(toString(#currentField),0,2)",
":",
"=substring(toString(#currentField),2,4)"
]
}
}
I need to use this column as a lookup column for another list, so I pasted this code and replaced #currentField with #currentField.LookupValue in the new lookup column as mentioned in https://github.com/SharePoint/sp-dev-docs/blob/master/docs/declarative-customization/column-formatting.md
The result is just showing ":". What do I have to do to make it work?
Regards,
Elio Fernandes
First, you need to use #currentField.lookupValue instead of #currentField.LookupValue, the first character of lookupValue should be lowercase.
And the code only works if the field in the parent list is Single line of text.
If the type of field in the parent list is Number, you need to change the code to this:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": {
"operator": "+",
"operands": [
"=substring(toString(#currentField.lookupValue),0,1)",
"=substring(toString(#currentField.lookupValue),2,3)",
":",
"=substring(toString(#currentField.lookupValue)3,5)"
]
}
}
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",
""
]
}
}
}