How to write common JS functionalities in SuiteCRM 7.10.*

You can use after_ui logic hook and inject from there.

See a tutorial here:

But watch out, it gets loaded in every request, and there are many kinds of requests.

I use a hook in one of my add-ons, and the beginning looks like this:

class PgrAfterUIHook
{

    function add_pgr_js()
    {
        // Exclusions:
        if (isset($GLOBALS["app"]) && $GLOBALS["app"]->controller->view === 'ajax') {
            return;
        }
        if (isset($_REQUEST['module'])) {
            $excludedModules = ['Home', 'Favorites', 'Administration', 'Reminders', 'ModuleBuilder', 'EmailMan'];
            if (in_array($_REQUEST['module'], $excludedModules)) {
                return;
            }
        }
        if (isset($_REQUEST['action'])) {
            $excludedActions = ['getFromFields', 'getDefaultSignatures', 'getEmailSignatures', 'send', 'EmailUIAjax', 'DynamicAction'];
            if (in_array($_REQUEST['action'], $excludedActions)) {
                return;
            }
        }
        if (!empty($_REQUEST['sugar_body_only']) && $_REQUEST['sugar_body_only']) {
            return;
        }

(...)

That uses a kind of “black-list” approach, excluding some kinds of requests. I found out each of this almost one by one, by getting bugs and broken functionality, investigating, and then finding out it was my own hook causing it.

I actually would recommend the opposite approach, like a “white-list”. Basically exclude every kind of request by default, and only allow in specific modules/views/actions you want.