How to change Command bar Button text for SlectionMode on SharePoint List

FUJISHIGE,Shuto/藤重 秀斗 0 Reputation points
2024-05-30T07:25:57.8533333+00:00

I have a question about formatting the command bar of a SharePoint list.

When [SelectionMode = NoSelection], I want to hide the "Automate" button.

When [SelectionMode = SingleSelection], I want to show the "Automate" button and set the text to "My Automate Start".

Can you tell me how to write this code?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,150 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,783 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 43,511 Reputation points Microsoft Vendor
    2024-05-31T08:49:36.7266667+00:00

    Per my test, you could only achieve one requirement once, cannot achieve two requirements at the same time.

    1.When [SelectionMode = NoSelection], I want to hide the "Automate" button.

    {
     "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
    "commandBarProps": {
    "commands": [
     {
    "key": "automate",
    "selectionModes": [
    "NoSelection"
     ],
    "hide": "true"
     }
     ]
     }
    }
    

    2.When [SelectionMode = SingleSelection], I want to show the "Automate" button and set the text to "My Automate Start".

    {
     "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
    "commandBarProps": {
    "commands": [
     {
    "key": "automate",
    "text": "My Automate Start",
    "selectionModes": [
    "SingleSelection"
     ],
    "hide": "false"
     }
     ]
     }
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.