2016-05-16 9 views
0

Ich bekomme das zu arbeiten, wenn ich eine bestimmte Liste auswählen, um die Aktion hinzuzufügen. Gibt es eine einfache Möglichkeit, diese benutzerdefinierte Aktion für alle Dokumentbibliotheken in der gesamten Websitesammlung zu aktivieren?SharePoint-Liste UserCustomAction, in ganzen sitecollection

Codebeispiel:

function createUserCustomActionList() { 
    var cmd = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" + 
     "<Button Id=\"DiaryAction.Button\" TemplateAlias=\"o1\" Command=\"DiaryCommand\" CommandType=\"General\" LabelText=\"Dela flera\" Image32by32=\"https://eolusvind.sharepoint.com/sites/intranet/_layouts/15/1033/Images/formatmap32x32.png?rev=23\"" + 
    " Image32by32Top=\"-271\" Image32by32Left=\"-109\" />" + 
     "</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" + 
      "<CommandUIHandler Command =\"DiaryCommand\" CommandAction=\"javascript:alert('Hej');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 1;\" />" + 
    "</CommandUIHandlers></CommandUIExtension>"; 

    var ctx = new SP.ClientContext.get_current(); 
    var list = ctx.get_web().get_lists().getByTitle('Dokument'); 
    var uca = list.get_userCustomActions(); 

    var oUserCustomAction = uca.add(); 
    oUserCustomAction.set_location('CommandUI.Ribbon.ListView'); 
    oUserCustomAction.set_commandUIExtension(cmd); 
    oUserCustomAction.set_sequence(100); 
    oUserCustomAction.set_title('Dela flera'); 
    oUserCustomAction.update(); 

    ctx.load(list, 'Title' ,'UserCustomActions'); 

    ctx.executeQueryAsync(function() { 
     alert('Custom action created for ' + list.get_title()) 
    }, function (sender, args) { 
     alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
    }); 
} 

Antwort

0

Ich würde vorschlagen, den folgenden Ansatz für benutzerdefinierte Schaltfläche Registrierung in Dokumenten-Bibliotheken über Websitesammlung:

  • Verwendung RegistrationType Satz 2 (Contenttype) und RegistrationId Set zu 0x0101 (für Document Inhaltstyp), um benutzerdefinierte Aktion über Inhaltstyp
  • zu registrieren verwenden Website Umfang Benutzer benutzerdefinierte Aktion, um die Änderungen in alle Website Sammlung

Beispiel

var cmd = "<CommandUIExtension>" + 
"<CommandUIDefinitions>" + 
"<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" + 
"<Button Id=\"ClickAction.Button\" TemplateAlias=\"o1\" Command=\"ViewCustomPropertiesCommand\" CommandType=\"General\" LabelText=\"View Custom Properties\" Image32by32=\"/_layouts/15/1033/Images/formatmap32x32.png?rev=23\" Image32by32Top=\"-1\" Image32by32Left=\"-171\" />" + 
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" + 
"<CommandUIHandler Command =\"ViewCustomPropertiesCommand\" CommandAction=\"javascript:console.log('View Custom Properties');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 0;\" />" + 
"</CommandUIHandlers>" + 
"</CommandUIExtension>"; 

var ctx = new SP.ClientContext.get_current(); 
var customAction = ctx.get_site().get_userCustomActions().add(); //1. apply via site scope user custom action 
customAction.set_location('CommandUI.Ribbon.ListView'); 
customAction.set_commandUIExtension(cmd); 
customAction.set_sequence(112); 
customAction.set_registrationType(2); //2.set to ContentType 
customAction.set_registrationId("0x0101"); //2.set Document content type 
//customAction.set_title('Document custom button'); 
customAction.update(); 

ctx.executeQueryAsync(function() { 
    console.log('Button has been registered'); 
}, function (sender, args) { 
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
}); 
+1

Nizza Vadim! Ich habe versucht, benutzerdefinierte Aktionen aus dem "Site" -Objekt zu laden, aber ich habe nicht Registrierungsart oder Registrierungs-ID verwendet. Vielen Dank! – simon