Creating Custom link in Site Setting and Site Action menu using JSOM

Here we are going to see how to add custom Site Action and Site Settings links in SharePoint Online, same code can be used for SharePoint 2013 and 2016. It’s very useful to provide our custom application navigation link in site action and custom application setting link Under site setting. This application provides easy user interaction.

cover 01

I have used custom page layout for developing this application and I used JSOM. If you are not familiar creating custom page layout, Check my previous post SharePoint custom page layout  .

In general, we have to use user custom action object to create link in site settings or site action menu. In that we have to pass the location and the group ID as a parameter, in the below table we can find out the all locations and group IDs for other possibilities.

list if group IDs

Sequence parameter will define top or bottom of the another link; Ex, 100 Sequence will place our link in the next to 99 Sequence link
Removing our custom link is very simple, we just have to loop all the custom links and filter the link based on link title, then we can remove the link object.

Adding custom link in site settings


var collUserCustomAction = web.get_userCustomActions();

var userCA = collUserCustomAction.add();
userCA.set_location('Microsoft.SharePoint.SiteSettings');
userCA.set_group("SiteAdministration");
userCA.set_sequence(100);
userCA.set_title('Custom SS Link');
userCA.set_url('http://www.google.com');
userCA.update();

clientContext.executeQueryAsync(function () {
console.clear();
console.log("Site settings link added");
}, OnFailure);

Adding custom link in site action menu


var collUserCustomAction = web.get_userCustomActions();

var userCA = collUserCustomAction.add();
userCA.set_location('Microsoft.SharePoint.StandardMenu');
userCA.set_group("SiteActions");
userCA.set_sequence(100);
userCA.set_description('Menu item added via ECMAScript');
userCA.set_title('Custom SA Link');
userCA.set_url('http://www.google.com');
userCA.update();

clientContext.executeQueryAsync(function () {
console.clear();
console.log("Site action link added");
}, OnFailure);

Removing custom link based on the link title


function removeCustomAction(title) {
var collUserCustomAction = web.get_userCustomActions();
clientContext.load(collUserCustomAction);
clientContext.executeQueryAsync(function () {
var item = collUserCustomAction.getEnumerator();
while (item.moveNext()) {
var currAction = item.get_current();
if (currAction.get_title() === title) {
currAction.deleteObject();
clientContext.load(currAction);
clientContext.executeQueryAsync(function () {
console.clear();
console.log(currAction.get_title() + " link removed");
}, OnFailure);
break;
}
}
}, OnFailure);
}

Please feel free to let me know if you have any queries in the comment section, I’m happy to help you!!

Happy coding!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s