1

Can we enable SPFx extension on a document created based on a specific content type.

I want to enable (make visible) ListViewCommandSet.CommandBar based on the document of certain content type selected which will enable me to perform certain actions for specific documents.

  • You will need to add more description here. It first glance question does not seem to be clear. – Asad Refai Aug 17 '18 at 9:04
1

It is not supported currently.

The List View commandset extension currently supports RegistrationType="List" and RegistrationId="100" which is the list template ID.

References - Command Set Extension: Ability to set RegistrationType="ContentType" and RegistrationId="0x01"

UserVoice Link - Support RegistrationType "ContentType" in Command Set Extensions

However, you can show/hide your commandset based on content type value:

In the onListViewUpdated method, you can get the current items content type value and then show/hide your extension somewhat as:

public onListViewUpdated(event: IListViewCommandSetListViewUpdatedParameters): void {
  const compareOneCommand: Command = this.tryGetCommand('COMMAND_1');
   if (compareOneCommand) {
    // ensure that atleast one item is selected
    if (event.selectedRows.length == 1) {

     // by default hide, the extension        

    compareOneCommand.visible = false;
    if(event.selectedRows[0].getValueByName("ContentType") == "<your-content-type-name>"){

     // show the extension if it matches your content-type
     compareOneCommand.visible = true;
     }
    }
   }
}
  • Thanks - workaround to check ContentType manually and toggle visibility worked as expected for now. one slight update I have to manually set visibility to false if condition not met. Visibility is bit temperamental in modern ui: compareOneCommand.visible = false; – Dev8055 Aug 17 '18 at 9:57
  • cheers, happy to help :) You can accept it as answer by ticking the checkmark besides the answer like this. By doing so, it will be removed from the unanswered section ! – Gautam Sheth Aug 17 '18 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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