SOLVED

replace text in field in json css

Iron Contributor

Hi all,

 

I am trying to replace the text in a list field depending on the content in the next column.  I don't even know if I am close, but I am struggling to figure out how to do it. See my json below.

 

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"font-weight": "=if([$Level_x0020_2_x0020_Term] !='','','bolder')",
"font-size": "=if([$Level_x0020_2_x0020_Term] !='','12px','16px')",
"font-style":
"=if([$Level_x0020_2_x0020_Term] !='','italic','')",
"display": "=if([$Level_x0020_2_x0020_Term] !='','none','')"

"content": "=if([$Level_x0020_2_x0020_Term] !='','&#x21B3','')"

}
}

 

If this is not possible, I would be fine with just replacing the text with an image I have as well.

3 Replies
best response confirmed by shawn_fielding (Iron Contributor)
Solution

Hi @shawn_fielding,

 

For the next column, try use a calculated field. 

 

Example:

 

Calculated Field Situation formula: 

IF([Age]>=21;"Allowed drink beer";IF([Age]>=18;"Allowed in some countries";Cant' drink beer))

 

| Age | Situation                             | 

| 10   | Cant' drink beer                  |
| 15   | Cant' drink beer                  | 
| 18   | Allowed in some countries | 

| 22   | Allowed drink beer             |

 

See more about SharePoint calculated fields formulas

 

To use icons or images using JSON, start using the samples:

https://github.com/sharepoint/sp-dev-list-formatting/tree/master/column-samples

 

 

 

 

@Paulo Junior you are a genius!  Thank you!  Using calculated fields based off the text fields was exactly what I needed, but a little css to make it look pretty.  Works beautifully!

@shawn_fielding

Before replacement, I feel that JSON format optimization will be more conducive to operation :) :smile:

You can format your JSON first here https://www.jsonformatting.com

 

1 best response

Accepted Solutions
best response confirmed by shawn_fielding (Iron Contributor)
Solution

Hi @shawn_fielding,

 

For the next column, try use a calculated field. 

 

Example:

 

Calculated Field Situation formula: 

IF([Age]>=21;"Allowed drink beer";IF([Age]>=18;"Allowed in some countries";Cant' drink beer))

 

| Age | Situation                             | 

| 10   | Cant' drink beer                  |
| 15   | Cant' drink beer                  | 
| 18   | Allowed in some countries | 

| 22   | Allowed drink beer             |

 

See more about SharePoint calculated fields formulas

 

To use icons or images using JSON, start using the samples:

https://github.com/sharepoint/sp-dev-list-formatting/tree/master/column-samples

 

 

 

 

View solution in original post