New in 83 - Web Client add-on menu items

Hey, wouldn't it be nice to be able to add my own menu items in the Web Client?  Yes it would and now you can, if you are willing to dirty your hands with a little JavaScript.

The code

This is the add-on that I included in the CustomScripts folder

//It's a good idea to wrap your code in a function to avoid conflict
//overriding existing variables and other addon
var RMVersionListAddon = function () {
    var buttonCaption = "Show all versions";
    var versionListButton = new HP.HPTRIM.Addon.RecordAddonButton({
        caption: buttonCaption,
        clickHandler: function () {
            var cntx = this.context;
            $.getJSON(HPRMWebConfig.virtualDirectory + "HPRMServiceAPI/Record?pageSize=2&q=allVersions:" + cntx.Uri, function (data) {
                if (data.Results && data.Results.length > 1) {
                    // window.location.href = '?t=Record&q=allVersions:' + cntx.Uri;
                    $('#global-search-input').val('allVersions:' + cntx.Uri);

                    var trimApp = window['root'];
                    trimApp.trimGlobalSearchPanel.search('allVersions:' + cntx.Uri);
                } else {
                    alert("There are no versions for this Record.")
                }
            });           
        }
    });

    //Prerender should have the context object
    versionListButton.preRender = function () {
        var record = this.context;
        if (record.RecordRecordType.RecordTypeAllowVersions.Value !== true) {
            this.setVisible(false);
        }
    };

    HP.HPTRIM.Addon.CustomScriptManager.register(versionListButton);

}();

Debugging

Don't forget you can swith debugging on to get a better view of your code, like this:

<compilation debug="true" targetFramework="4.5" />


Written on December 7, 2015