Monthly Archives: February 2014

Custom site actions using JS in SharePoint 2013

Recently, moving to the cloud from on premises has been the talk of the town.

So, I decided to explore to move couple of my existing solutions or customization to be cloud ready.  One among them would be the modification of custom site actions in “Welcome” menu and “Site Actions” aka “Gear” control in SharePoint 2013.

The JS implementation would be like below:

<SharePoint:ScriptLink language=”javascript” name=”SP.js” runat=”server” LoadAfterUI=”true” />
<script type=”text/javascript”>

ExecuteOrDelayUntilScriptLoaded(retrieveWebSite, “sp.js”);

function retrieveWebSite() {
var clientContext = new SP.ClientContext.get_current();
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(1000);
oUserCustomAction.set_title(‘ECMA Website’);

oUserCustomAction.update();

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());}

</script>

The same can be achieved for Welcome menu by making “PersonalActions” as the Group.

For the full list of Custom Action Locations and IDs, please refer – http://msdn.microsoft.com/en-us/library/office/bb802730.aspx

Advertisements