1

I am creating a custom action on a SharePoint Online site. I would like a button to pop up for all docx file types in a specific document library, not all document libraries.

it looks like I only have the choice either File Type OR choose List ID, not both. Is it possible to do both somehow?

<CustomAction
  RegistrationType = "ContentType"
  RegistrationId=">
</CustomAction>

The above will show in every document library for docx OR:

<CustomAction
  RegistrationType = "List"
  RegistrationId="listId">
</CustomAction>

the above will show for all file types on a document library

0

I think you can add your action only to specific document library. No additional parameters needed.
Here you can see that SP.List object has userCustomActions property. It is what you need.
You can add custom action like this by js from browser console.
Here good guide how to do that but I copy-paste just in case
:

var siteUrl = '/sites/MySiteCollection';

function createUserCustomActionList() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    this.oList = oWebsite.get_lists().getByTitle('My List');
    var collUserCustomAction = oList.get_userCustomActions();

    var oUserCustomAction = collUserCustomAction.add();
    oUserCustomAction.set_location('EditControlBlock');
    oUserCustomAction.set_sequence(100);
    oUserCustomAction.set_title('My First User Custom Action');
    oUserCustomAction.set_url(siteUrl + '/_layouts/MyPage.aspx');
    oUserCustomAction.update();

    clientContext.load(oList, 'Title' ,'UserCustomActions');

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    alert('Custom action created for ' + this.oList.get_title());}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

Change list name to yours, action settings to yours and execute this in browser console on any list item form (here you have all scripts loaded - SP.ClientContext and etc must work here - may be list view also have all scripts - I don't remember).

| improve this answer | |

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.