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, ',', '')"
}
Related
I currently started working with Sharepoint and need to create a list the involves personal information (Name, Surname, Description, ...). Maybe some background to what I want to do.
For filtering purpose I have added a dummy line that has all those fields filled with "!". In my last column I want to create a button that allows me to trigger a PowerAutomate flow in order to copy all mails. Now this is were I am stuck. This button I want to create should only be available in the dummy line, where e.g. the field name is filled with "!" but so far I only managed to display my button in all rows and not just the dummy row. I thought about creating an if-statement that checks the field/column "name" for "!" and if that is the case, I want to create the button, but since I am quite new to Sharepoint/JSON I have trouble figuring out what is the exact problem and why my code is not working.
So far I tried to find a solution for my problem, but only came up with this here, which is not quite working. I would really appreciate some help. Thank you very much in advance guys! :)
Edit: A link to the picture for my sharepoint list is below the code :)
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"if" : {
"name" : "!"
},
"then" : [
{
"txtContent": "Copy",
"attributes": {
"href": "='Here the link to my PowerAutomate-Flow will be pasted'"}
}
],
"else" : [
{
"txtContent": "",
"attributes":{
"href": "=''"}
}
],
"style": {
"padding": "0px 25px",
"cursor": "pointer",
"border": "none",
"color": "white",
"font-weight": "550",
"background-color": "#0078d4",
"text-decoration": "none",
"font-size": "14px",
"text-align": "center",
"width": "35px"
}
}
[My Sharepoint-List](https://i.stack.imgur.com/Dj7RK.png)
Here is a similar case for you to refer to:
https://learn.microsoft.com/en-us/answers/questions/737561/displaynot-dispaly-through-fromat-column-in-sharep.html?childToView=737760#answer-737760
In this case, if the status column is equal to 'Closed', then the button will not work. If not, there will be a button to trigger a flow.
As the button you want to create should only be available in the dummy line, where e.g. the field name is filled with "!", you could modify the code like this:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"elmType": "button",
"customRowAction": {
"action": "executeFlow",
"actionParams": "{\"id\": \"386b81a1-fce2-45da-a981-91160d0d9245\"}"
},
"attributes": {
"class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
},
"txtContent": "copy",
"style": {
"border": "none",
"background-color": "lightgreen",
"cursor": "pointer",
"display": "=if([$name]=='!','inherit','none')"
}
},
{
"elmType": "span",
"style": {
"padding-right": "8px",
"display": "=if([$name]=='!','none','inherit')"
},
"txtContent": "#currentField"
}
]
}
You could change the parameter in the code according to your own requirement, for example: the "actionParams": "{"id": "386b81a1-fce2-45da-a981-91160d0d9245"}" is generated by the flow I created, you need to change it into your own flow id.
I am working on a document checklist for my users and my second column 'Description' currently has the '?' in it. Currently the code allows the user to hover over the '?' and see a further description if needed as below.
I would like to replace with the '?' with an image, similar to a tooltip ? to ensure the list looks clean. I was wondering if this was possible in Sharepoint online. This is the current code I have.
{"$schema":"https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json","elmType":"div","style":{"font-size":"12px"},"txtContent":"?","customCardProps":{"formatter":{"elmType":"div","txtContent":"[$Description]","style":{"font-size":"12px","color":"green","padding":"5px"}},"openOnEvent":"hover","directionalHint":"bottomCenter","isBeakVisible":true,"beakStyle":{"backgroundColor":"white"}}}
Is this a simple replacement of a code or would this require a more complicated process?``
We can add iconName attribute as shown below:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"style": {
"font-size": "12px"
},
"attributes": {
"iconName": "SunQuestionMark"
},
"customCardProps": {
"formatter": {
"elmType": "div",
"txtContent": "[$Description]",
"style": {
"fontsize": "12px",
"color": "green",
"padding": "5px"
}
},
"openOnEvent": "hover",
"directionalHint": "bottomCenter",
"isBeakVisible": true,
"beakStyle": {
"backgroundColor": "white"
}
}
}
My test result for your reference:
I have a column in a ShP list where I need whatever figure we enter to change colour according to the range they fit in:
red for <= 50, amber for =>51 and green for >75
I have it working for two ranges but I am still trying to figure out the format into which I should write a range of numbers between >51 and <74 but I have yet to find the format to write it down.
Here's what I have working so far:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(#currentField <= 50,'sp-field-severity--blocked', if(#currentField >75,'sp-field-severity--good','')"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block",
"padding": "0 4px"
},
"attributes": {
"iconName": "=if(#currentField <= 50,'SadSolid', if(#currentField >75,'Emoji2', '')"
}
},
{
"elmType": "span",
"txtContent": "#currentField"
}
]
}
Can anyone see what I'm missing? I can't be far off... I have managed to fit in a second condition today and it works. Last one to go.
I've been trying to change the background color of a column in a Sharepoint list without full success.
I've been using below JSON code but what bugs me is that it don't fill out the whole cell.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"debugMode": true,
"txtContent": "#currentField",
"style": {
"background-color": "pink"
}
}
Current sharepoint list
Do you have any ideas on how to solve this?
Thanks
This is due to the min-height property set.
As a workaround, you could enlarge the min-height to make it fill out the whole cell.
Example:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"debugMode": true,
"txtContent": "#currentField",
"style": {
"min-height":"56px",
"background-color": "pink"
}
}
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)"
]
}
}