SOLVED

JSON Column Formatting help with Condition statement for displaying Hyperlink alternate txt

Copper Contributor

I have a SharePoint list, which I have a single line of text column that will contain an URL link.  To start with this column is blank and does not show on the new for item form.  It gets populated by power automate when the flow creates a file in a whiteboard document library and and the next step in the flow after creating the document in the "Whiteboard" document library is to update the URL single line of text column with the link to the file it created in the previous step if the flow.  I would like to display this column as a clickable link using JSON column formatting and I have found the following code to display the URL as a link and the alternate text as "whiteboard" and it works.  However, if the field is blank I would like to leave the field displayed as blank, instead of "Whiteboard". Right now while it works, it displays "Whiteboard" for every item, even if the field is blank before the flow triggers and has a chance to populate it.  I would like to modify the code I am using to make the field show nothing in the column if the column is left blank and then once the flow populates the column, the have it show the alternate text as "whiteboard". 

Can anybody suggest how to modify this so it will still display "Whiteboard" if the the column is not blank, but if the column is blank, then to display the column as blank? 

OR

Can somebody suggest how to modify the code with an IF statement where it shows the txtContent as "whiteboard" only if the column is not null otherwise shows the txtContent as "Creating"

 

Here is the code I am using:

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "a",
"attributes": {
"href": "@currentField",
"target": "_blank"
},
"txtContent": "Whiteboard"
}

3 Replies

@Oberke2380 Use below JSON code: 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "style": {
        "display": "=if(@currentField == '', 'none', 'block')"
    },
    "attributes": {
        "href": "@currentField",
        "target": "_blank"
    },
    "txtContent": "Whiteboard"
}

 

Output:

 

ganeshsanap_0-1657882940308.png


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Thanks, This works!
Is there way to modify it where instead of being blank when Column is empty, it says "Creating Whiteboard" ? (Since its only a short amount of time until the flow triggers and creates the whiteboard and populates this field with a link.

best response confirmed by Oberke2380 (Copper Contributor)
Solution

@Oberke2380 Use this JSON: 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "children": [
        {
            "elmType": "a",
            "style": {
                "display": "=if(@currentField == '', 'none', 'block')"
            },
            "attributes": {
                "href": "@currentField",
                "target": "_blank"
            },
            "txtContent": "Whiteboard"
        },
        {
            "elmType": "span",
            "style": {
                "display": "=if(@currentField == '', 'block', 'none')"
            },
            "txtContent": "Creating Whiteboard"
        }
    ]
}

 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

1 best response

Accepted Solutions
best response confirmed by Oberke2380 (Copper Contributor)
Solution

@Oberke2380 Use this JSON: 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "children": [
        {
            "elmType": "a",
            "style": {
                "display": "=if(@currentField == '', 'none', 'block')"
            },
            "attributes": {
                "href": "@currentField",
                "target": "_blank"
            },
            "txtContent": "Whiteboard"
        },
        {
            "elmType": "span",
            "style": {
                "display": "=if(@currentField == '', 'block', 'none')"
            },
            "txtContent": "Creating Whiteboard"
        }
    ]
}

 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

View solution in original post