SharePoint Online - Lookup Display multiples values in Form - json

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

Related

JSON Formatting on SharePoint List column to enable cascading dropdown

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 )

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 Online - JSON column formatting

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

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

How SharePoint JSON Script look other column

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