I was looking for a way if JSON Script can look other column and format other column. base on the value of the other column.
Is there an alternate way to use "#currentfield"?
Thanks
Check the Apply formatting based on date ranges demo.
{
"elmType": "div",
"txtContent": "#currentField",
"style": {
"color": {
"operator": "?",
"operands": [
{
"operator": "<=",
"operands": [
"[$DueDate]",
"#now"
]
},
"#ff0000",
""
]
}
}
}
The MS Docs link #Lee_MSFT provided has some decent examples on formatting. In addition to the notes on internal/field names in the discussion on date ranges, the doc includes instructions for cross-referencing other columns (https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#fieldname). Essentially, if you want to reference/use data from column A to format column B, you will need to use the "internal name" of column A in the JSON formatting on column B. A column name may be (and often is) different than the "display name" of the column. For example, we have a basic list for tracking some team members:
"Alias/Logon" (SLOT); internal name: Title
"First Name" (SLOT); internal name: FirstName
"Last Name" (SLOT); internal name: LastName
"Current Contracts" (SLOT); internal name: CurrentContracts
We want "Current Contracts" to be a URL link that uses the "Alias/Logon" value and we also want to display an icon. In fact, this column doesn't even require content as it will show an actual icon and the word "Contracts" for all users. Obviously, if you reference a column that is not mandatory, you should do some data validation to ensure you aren't creating bad URLs, etc.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "a",
"attributes": {
"target": "_blank",
"iconName": "BulletedList",
"class": "sp-field-quickActions",
"href": {
"operator": "+",
"operands": [
"https://mycompany.sharepoint.com/teams/coolpeople/contracts/",
"[$Title]"
]
}
},
"txtContent": "Contracts"
}
Note: just do a search for "SharePoint JSON column formatting" to find a plethora of examples, including the repo on GitHub (https://github.com/SharePoint/sp-dev-list-formatting).
Related
I am new to JSON and working on formatting a calendar within Microsoft Lists. I hope what I'm asking is an easy fix!
Essentially, the goal is to highlight on the calendar when a meeting contains the word "Nick" even though the meetings have different names. (ex. Nick: Review, Nick: Email, Nick: FYI)
My code (generated by Microsoft) is below.
{
"$schema": "//link removed",
"additionalEventClass": {
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
"[$Title]",
"Nick: Review"
]
},
"=if(#isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgBlue' , 'sp-css-backgroundColor-BgCornflowerBlue sp-css-color-CornflowerBlueFont')",
"=if(#isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgGray' , 'sp-css-backgroundColor-BgLightGray sp-css-color-LightGrayFont')"
]
}
}
I have been googling for contains functions or something using an asterisk similar to what I've used in other languages, but I'm unclear on how to integrate.
Problem: I want to search the description for "Vacation" in a string that reads "Name (Vacation)". there are many different Names, Name 1, Name 2, etc. the word "Vacation" is constant, I want to create 1 condition that formats all variations of Vacation.
I have played around with the operator changing "operator": "==", with no luck. Example "in", "$in", etc.
Is there an easy solution that I am missing?
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/calendar-formatting.schema.json",
"additionalEventClass": {
"operator": ":",
"operands": [
{
"operator": "==",
"operands": [
"[$Title_x0020_Category]",
"Name (Vacation)"
]
},
"=if(#isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgGreen' , 'sp-css-backgroundColor-BgMintGreen sp-css-color-MintGreenFont')",
""
]
}
}
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 an adaptive card in the form of a JSON file, which contains an Input.ChoiceSet. This is provided with a data payload, which is dynamic and so it is not the same amount of data every time. I want to be able to drop this Input.ChoiceSet if it breaks a certain threshold based on the length of the array of data that I'm going to pass to it. Is it possible to write this as an condition inside the Input.ChoiceSet using %when to carry this out?
This is currently what I have, but it is not working as I would've hoped:
{
"type": "Input.ChoiceSet",
"id": "CompactSelectVal1",
"$when": "${$data.length < 400}",
"placeholder": "Select a value",
"choices": [
{
"$data": "${data}",
"title": "${name}",
"value": "${tag}"
}
],
"label": "Input"
}
Using .length here was just a guess here, not based on any documentation. The documentation I have used to find out about $when is the following https://learn.microsoft.com/en-us/adaptive-cards/templating/language.
Any help on this would be much appreciated.
You can use "count" property instead of "length" and also remove the extra '$' inside the curly bracket "${$data.length < 400}".
Try this:
{
"type": "Input.ChoiceSet",
"id": "CompactSelectVal1",
"$when": "${count(data) < 400}",
"placeholder": "Select a value",
"choices": [
{
"$data": "${data}",
"title": "${name}",
"value": "${tag}"
}
],
"label": "Input"
}
If the condition is true then the choice button will hide from the adaptive card.
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)"
]
}
}