Health and Wellness ๐ŸŒฟ Fashion and Beauty ๐ŸŒธ Love, Home, and Family ๐ŸŒน Science ๐Ÿ”ฌ and Programming ๐Ÿ’ป

Lipstick, Wine, and Heels

Lipstick, Wine, and Heels

Health and Wellness ๐ŸŒฟ Fashion and Beauty ๐ŸŒธ Love, Home, and Family ๐ŸŒน Science ๐Ÿ”ฌ and Programming ๐Ÿ’ป

Why Teamwork Beats Solopreneurship

Why Teamwork Beats Solopreneurship

I’ve been an independent contractor, a freelancer, in my web development career for about eight years. Until September of last year, I was a solo act. I did a little of everything – project management, design, front end and back end development, sales … everything […]

How To Not Get a Cold or Flu During Cold & Flu Season

How To Not Get a Cold or Flu During Cold & Flu Season

Today was a lovely, warm day, and I relished the opportunity to take a walk around the park without layering up. ย So this may not seem like the most timely post considering that spring is just around the corner. However, I felt that I needed […]

Adding a custom menu item to the SharePoint gear menu with Javascript

Adding a custom menu item to the SharePoint gear menu with Javascript

Adding a custom menu item to the SharePoint gear menu using Javascript is easy, but there isn’t a lot of documentation on how to do this in practice. Here is a script you can insert wherever you are adding any custom Javascript, whether in a custom script file or in the script editor. As soon as the page with the script is loaded, it will check if the menu item exists. If not, it will add it. Lines 30-35 is where you can set the properties of the custom menu item.

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', GetCustomActions);
    var clientContext, 
        oWeb, 
        collUserCustomAction;
    function GetCustomActions () {
        //Get the client context and web object 
        clientContext = new SP.ClientContext();
        oWeb = clientContext.get_web();
        //Get the custom user action collection and add the new custom action to it   
        collUserCustomAction = oWeb.get_userCustomActions(); 
        clientContext.load(collUserCustomAction);  
        clientContext.executeQueryAsync(AddCustomAction, QueryFailure); 
    }
    function AddCustomAction () {
        var customActionEnumerator = collUserCustomAction.getEnumerator();
        var isDashboard = false;

        while (customActionEnumerator.moveNext()) 
        {
            var oUserCustomAction = customActionEnumerator.get_current();

            if (oUserCustomAction.get_title() == 'Dashboard') 
            {
                isDashboard = true;
            }
        }
        if(isPresNetAdmin === false) {
            var oUserCustomAction = collUserCustomAction.add();  
            //Specify the location and properties for the new custom action   
            oUserCustomAction.set_location('Microsoft.SharePoint.StandardMenu');  
            oUserCustomAction.set_sequence(101);  
            oUserCustomAction.set_group('SiteActions');  
            oUserCustomAction.set_title("Dashboard");  
            oUserCustomAction.set_url("/Pages/dashboard.aspx");
            oUserCustomAction.update(); 
            //Load the client context and execute the batch 
            clientContext.load(oUserCustomAction);
            clientContext.executeQueryAsync(QuerySuccess,QueryFailure);
        }
    }

    function DeleteCustomAction()
    { 
        var customActionEnumerator = collUserCustomAction.getEnumerator();

        while (customActionEnumerator.moveNext()) 
        {
            var oUserCustomAction = customActionEnumerator.get_current();

            if (oUserCustomAction.get_title() == 'Dashboard') 
            {
            oUserCustomAction.deleteObject();
            clientContext.load(oUserCustomAction);
            clientContext.executeQueryAsync(QueryDeleteSuccess,QueryFailure);
            }
        }
    }
  
    function QuerySuccess() {  
        console.log("New Custom User Action has been added to site settings");  
    } 

    function QueryDeleteSuccess() {  
        console.log("Custom action has been deleted");  
    }  
  
    function QueryFailure() {   
        console.error('Error')
    }

Additional reading

Staying Slim with a Sedentary Job

Staying Slim with a Sedentary Job

Many of us, especially those of us in the programming industry, have long, sedentary days glued to our computers. Though I have been blessed with being naturally thin, I realize this won’t last forever. Besides weight gain, a sedentary lifestyle leads to a host of […]

Why Whiteboarding Weeds Out Great Developers

Why Whiteboarding Weeds Out Great Developers

The only interview I came out of feeling that I did quite poorly, was one with a whiteboarding series of tests, albeit it was on paper rather than on a whiteboard. I felt that I had failed quite miserably inย even presenting myself as a programmer, […]