Kirill Gonchar
Kirill Gonchar

Reputation: 16

SharePoint Column Formatting: JSON "@currentField.lookupValue" throws error in case of blank lookup value

I've got a SharePoint List with the column "Status - Overall (lookup)" which type is "Lookup". It gets information from another list and there can be only 5 values: "Red", "Amber", "Green", "Gray" or blank value.

I applied conditional column formatting to the column "Status - Overall (lookup)" according to the article: https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting

Here's JSON code which was pasted into "Column Formatting" setting of the List Column:

{
"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
"debugMode": true,
"elmType": "div",
"attributes": {
    "class": {
        "operator": "?",
        "operands": [
            {
                "operator": "==",
                "operands": [
                    {
                        "operator": "toString()",
                        "operands": [
                            "@currentField.lookupValue"
                        ]
                    },
                    "Green"
                ]
            },
            "sp-field-severity--good",
            {
                "operator": "?",
                "operands": [
                    {
                        "operator": "==",
                        "operands": [
                            {
                                "operator": "toString()",
                                "operands": [
                                    "@currentField.lookupValue"
                                ]
                            },
                            "Gray"                            ]
                    },
                    "sp-field-severity--low",
                    {
                        "operator": "?",
                        "operands": [
                            {
                                "operator": "==",
                                "operands": [
                                    {
                                        "operator": "toString()",
                                        "operands": [
                                            "@currentField.lookupValue"
                                        ]
                                    },
                                    "Amber"
                                ]
                            },
                            "sp-field-severity--warning",
                            {
                                "operator": "?",
                                "operands": [
                                    {
                                        "operator": "==",
                                        "operands": [
                                            {
                                                "operator": "toString()",
                                                "operands": [
                                                    "@currentField.lookupValue"
                                                ]
                                            },
                                            "Red"
                                        ]
                                    },
                                    "sp-field-severity--severeWarning",
                                    "sp-field-severity--blocked"
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
},
"children": [
    {
        "elmType": "span",
        "style": {
            "display": "inline-block",
            "padding": "0 4px"
        },
        "attributes": {
            "iconName": {
                "operator": "?",
                "operands": [
                    {
                        "operator": "==",
                        "operands": [
                            {
                                "operator": "toString()",
                                "operands": [
                                    "@currentField.lookupValue"
                                ]
                            },
                            "Green"
                        ]
                    },
                    "CheckMark",
                    {
                        "operator": "?",
                        "operands": [
                            {
                                "operator": "==",
                                "operands": [
                                    {
                                        "operator": "toString()",
                                        "operands": [
                                            "@currentField.lookupValue"
                                        ]
                                    },
                                    "Amber"
                                ]
                            },
                            "Forward",
                            {
                                "operator": "?",
                                "operands": [
                                    {
                                        "operator": "==",
                                        "operands": [
                                            {
                                                "operator": "toString()",
                                                "operands": [
                                                    "@currentField.lookupValue"
                                                ]
                                            },
                                            "Gray"
                                        ]
                                    },
                                    "Error",
                                    {
                                        "operator": "?",
                                        "operands": [
                                            {
                                                "operator": "==",
                                                "operands": [
                                                    {
                                                        "operator": "toString()",
                                                        "operands": [
                                                            "@currentField.lookupValue"
                                                        ]
                                                    },
                                                    "Red"
                                                ]
                                            },
                                            "Warning",
                                            "ErrorBadge"
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        }
    },
    {
        "elmType": "span",
        "txtContent": "@currentField.lookupValue"
    }
]}

This JSON works fine for all lookup values except the blank value which displays the following error:

(column-internal-name).lookupValue was not found on the data object.

enter image description here

Is there a way to fix that?

Upvotes: 0

Views: 6069

Answers (1)

Kirill Gonchar
Kirill Gonchar

Reputation: 16

I have got the respond here: https://github.com/SharePoint/sp-dev-column-formatting/issues/36

The resolution is to change "debugMode" from 'true' to 'false'. Now conditional formatting works fine, without any errors.

Upvotes: 0

Related Questions