4

It is possible to add custom links to the site actions (gear menu) in SharePoint 2013 from SharePoint Designer?

I've found some solutions that use features and elements but i'm not looking those solutions. In SharePoint 2010 was possible to do this. How could i do it with SP2013?

1 Answer 1

6

You can. MSDN actually has an example of how to do this with JavaScript CSOM. You can add this thru SharePoint Designer and embed directly in a page, reference it as a file, or you can even just drop it into a script web part.

MSDN: https://msdn.microsoft.com/en-us/library/office/hh185004%28v=office.14%29.aspx

function createUserCustomActionSite() {

    var clientContext = new SP.ClientContext(siteUrl);
    this.oWebsite = clientContext.get_web();
    var collUserCustomAction = oWebsite.get_userCustomActions();

    var oUserCustomAction = collUserCustomAction.add();
    oUserCustomAction.set_location('Microsoft.SharePoint.StandardMenu');
    oUserCustomAction.set_group('SiteActions');
    oUserCustomAction.set_sequence(101);
    oUserCustomAction.set_title('ECMA Website User Custom Action ECMA');
    oUserCustomAction.set_description('This description appears on the Site Actions menu.');
    oUserCustomAction.set_url(siteUrl + '/_layouts/jstest2.aspx');
    oUserCustomAction.update();

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

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

function onQuerySucceeded(sender, args) {

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

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
2
  • I don't know what I couldn't include the user action with your code (or the MSDN example) but it was a good start. You gave me the key to find a similar soultion: aaclage.blogspot.com/2013/12/…. Thank you, I was stuck with this
    – yngrdyn
    Mar 17, 2015 at 12:48
  • The thing is you need to call the function when all is loaded, so you can do it like this: $(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(createUserCustomActionSite, "sp.js"); });
    – yngrdyn
    Mar 17, 2015 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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