SOLVED

replace text in field in json css

%3CLINGO-SUB%20id%3D%22lingo-sub-1123256%22%20slang%3D%22en-US%22%3ERe%3A%20replace%20text%20in%20field%20in%20json%20css%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1123256%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F406546%22%20target%3D%22_blank%22%3E%40shawn_fielding%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20the%20next%20column%2C%20try%20use%20a%20calculated%20field.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExemple%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECalculated%20Field%20Situation%20formula%3A%26nbsp%3B%3C%2FP%3E%3CP%3EIF(%5BAge%5D%26gt%3B%3D21%3B%22Allowed%20drink%20beer%22%3BIF(%5BAge%5D%26gt%3B%3D18%3B%22Allowed%20in%20some%20countries%22%3BCant'%20drink%20beer))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%7C%20Age%20%7C%20Situation%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7C%26nbsp%3B%3C%2FP%3E%3CP%3E%7C%2010%26nbsp%3B%20%26nbsp%3B%7C%26nbsp%3BCant'%20drink%20beer%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7C%3CBR%20%2F%3E%7C%2015%26nbsp%3B%20%26nbsp%3B%7C%26nbsp%3BCant'%20drink%20beer%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7C%26nbsp%3B%3CBR%20%2F%3E%7C%2018%26nbsp%3B%20%26nbsp%3B%7C%20Allowed%20in%20some%20countries%20%7C%26nbsp%3B%3C%2FP%3E%3CP%3E%7C%2022%26nbsp%3B%20%26nbsp%3B%7C%26nbsp%3BAllowed%20drink%20beer%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsupport.office.com%2Fen-us%2Farticle%2Fexamples-of-common-formulas-in-sharepoint-lists-d81f5f21-2b4e-45ce-b170-bf7ebf6988b3%3Fui%3Den-US%26amp%3Brs%3Den-US%26amp%3Bad%3DUS%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESee%20more%20about%20SharePoint%20calculated%20fields%20formulas%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20use%20icons%20or%20images%20using%20JSON%2C%20start%20using%20the%20samples%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsharepoint%2Fsp-dev-list-formatting%2Ftree%2Fmaster%2Fcolumn-samples%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fsharepoint%2Fsp-dev-list-formatting%2Ftree%2Fmaster%2Fcolumn-samples%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1122671%22%20slang%3D%22en-US%22%3Ereplace%20text%20in%20field%20in%20json%20css%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1122671%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20trying%20to%20replace%20the%20text%20in%20a%20list%20field%20depending%20on%20the%20content%20in%20the%20next%20column.%26nbsp%3B%20I%20don't%20even%20know%20if%20I%20am%20close%2C%20but%20I%20am%20struggling%20to%20figure%20out%20how%20to%20do%20it.%20See%20my%20json%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%7B%3CBR%20%2F%3E%22%24schema%22%3A%20%22%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fv2%2Fcolumn-formatting.schema.json%3C%2FA%3E%22%2C%3CBR%20%2F%3E%22elmType%22%3A%20%22div%22%2C%3CBR%20%2F%3E%22txtContent%22%3A%20%22%40currentField%22%2C%3CBR%20%2F%3E%22style%22%3A%20%7B%3CBR%20%2F%3E%22font-weight%22%3A%20%22%3Dif(%5B%24Level_x0020_2_x0020_Term%5D%20!%3D''%2C''%2C'bolder')%22%2C%3CBR%20%2F%3E%22font-size%22%3A%20%22%3Dif(%5B%24Level_x0020_2_x0020_Term%5D%20!%3D''%2C'12px'%2C'16px')%22%2C%3CBR%20%2F%3E%22font-style%22%3A%3CBR%20%2F%3E%22%3Dif(%5B%24Level_x0020_2_x0020_Term%5D%20!%3D''%2C'italic'%2C'')%22%2C%3CBR%20%2F%3E%22display%22%3A%20%22%3Dif(%5B%24Level_x0020_2_x0020_Term%5D%20!%3D''%2C'none'%2C'')%22%3C%2FP%3E%3CP%3E%22content%22%3A%20%22%3Dif(%5B%24Level_x0020_2_x0020_Term%5D%20!%3D''%2C'%26amp%3B%23x21B3'%2C'')%22%3C%2FP%3E%3CP%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20this%20is%20not%20possible%2C%20I%20would%20be%20fine%20with%20just%20replacing%20the%20text%20with%20an%20image%20I%20have%20as%20well.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1122671%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELists%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
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.

2 Replies
Highlighted
Best Response confirmed by shawn_fielding (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

 

 

 

 

Highlighted

@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!