locked
Column Format not working RRS feed

  • Question

  • Hello friends,

    i have problem with my column format code.
    It is not working. Do you have any idea why?

    It should only, based on another field in that view, decide what background color the column must have.
    Please look at my code. What is wrong with that?

    {
        "elmType": "div",
        "style": {
           "background-color": {
              "operator": "?",
              "operands": [
                 {
                    "operator": "==",
                    "operands": [
                       "[$UK_Project]",
                       "Holiday"
                    ]
                 },
                 "lightblue",
                 {
              "operator": "?",
              "operands": [
                 {
                    "operator": "==",
                    "operands": [
                       "[$UK_Project]",
                       "sickness"
                    ]
                 },
                 "orange"
              ]
           }
              ]
           }
        }
     }

    Would nice to hear if you have any ideas.

    Best regards

    Basti


    • Edited by Basti087 Monday, December 9, 2019 3:41 PM
    Monday, December 9, 2019 3:20 PM

All replies

  • Hi Basti,

    Try to modify as below:

    {
       "$schema": 
       "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
       "elmType": "div",
       "debugMode": true,
       "txtContent": "@currentField",
       "style": {
           "color": "=if([$UK_Project] == 'Holiday', 'lightblue', if([$UK_Project] == 'sickness','orange',''))"
       }
    }

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, December 10, 2019 2:39 AM
  • ...strange it is not working at my side.

    I got a error message back, that the syntax contains not allowed characters.
    It displays that theese are: ( ! & : ;

    We use Sharepoint 2019 on-prem

    Basti

    Tuesday, December 10, 2019 9:05 AM
  • I tried it now with an easy field. I used the Created field with the following formular, copied from here:
    https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      "elmType": "div",
      "debugMode": true,
      "txtContent": "@currentField",
      "style": {
        "color": "=if([$Created] <= @now, '#ff0000', '')"
      }
    }


    I receive in the column a error message:

    Failure: The Style Value "=if([$Created] &lt;= @now, &#39;#ff0000&#39;, &#39;&#39;)" contains at least one of the following invalid characters ( : & ; ! .

    Any ideas, whats wrong here?


    Tuesday, December 10, 2019 11:05 AM
  • Hi Basti,

    The error specify the '' character in the style has been encoded to &#39;. 

    I will test this point in my environment tomorrow and then give you updates.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, December 10, 2019 11:37 AM
  • Hi Basti,

    I have tested the Json code in SharePoint 2019 environment and reproduce this issue in my side also:

    In the post above, I'm testing in SharePoint Online firstly, it's working as expected.

    Then I also tested with the demo from Official document, still the same error, for this, I would suggest you could create a issue ticket to report this issue in GitHub:

    https://github.com/SharePoint/sp-dev-docs/issues

    Thanks

    Best Regards 


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, December 12, 2019 9:40 AM
  • Thanks, Jerry.

    I have created the issue report:
    https://github.com/SharePoint/sp-dev-docs/issues/5014

    Best regards
    Basti

    Thursday, December 12, 2019 10:08 AM