3

I'm currently using SharePoint column formatting JSON to turn a field's string entry into a text, based on it's value.

For instance:

  1. whenever @currentfield is equal to number 10, it should replace the number 10 with "Hello"

  2. whenever @currentfield is equal to number 20, it should replace the number 20 with "Bye",

  3. Otherwise do nothing.

Is there a simple way to do that?

1 Answer 1

2

Use below JSON for you column:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(@currentField == 10, 'Hello', if(@currentField == 20, 'Bye', ''))"
}

Output:

Before applying JSON:

enter image description here

After applying JSON:

enter image description here


If you want to keep @currentField value as it is for 3rd condition, use:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=if(@currentField == 10, 'Hello', if(@currentField == 20, 'Bye', @currentField))"
}

Output:

enter image description here

1
  • Hi @Sarmad, does this answer your question? Commented Jun 25, 2022 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.