Using FogBugz On Demand? We've recently rolled out a new sidebar as part of taking FogBugz forward. Please see this article for details on what's new, what's changed, and where you can find all your favorite things.

If you add javascript to the page and just call it, it will run on every page-load. If you want to limit to just case edit, or assign, or another, use this code:

$(function(){

    // if we're not on the case page, don't do anything
    if (!$('#bugviewContainer').length) return;

    var myFunction = function(sCommand) {
        // you can put a conditional in here if you only want to
        // run your code for certain modes by looking at sCommand.
        // the possible values are:
        // load, view, edit, assign, reply, forward, resolve,
        // close, reactivate, reopen, new

        // on initial page load, sCommand will be 'load'
        // on viewing a case after canceling an AJAXy action, e.g.
        // canceling an edit, sCommand will be 'view'
        // on page load of the new case page, sCommand will be 'new'
    };

    if ($('#sEventEdit').length > 0)
    {
        myFunction('new');
    }
    else if ($('#sEventReply').length > 0)
    {
        myFunction('reply');
    }
    else if ($('#sEventForward').length > 0)
    {
        myFunction('forward');
    }
    else {
        myFunction('load');
    }

    // run it when the view changes and pass in the new view:
    $(window).on('BugViewChange', function(e, data) {
        myFunction(data.sCommand); 
    });

});

To help figure out what commands are happening, put this as the first line inside of myFunction():

console.log(sCommand);

If you find that your code (myFunction) is not firing on some or all types of page-loads, you can add a delay:

$(function(){

    // if we're not on the case page, don't do anything
    if (!$('#bugviewContainer').length) return;

    var myFunction = function(sCommand) {
        // you can put a conditional in here if you only want to
        // run your code for certain modes by looking at sCommand.
        // the possible values are:
        // load, view, edit, assign, reply, forward, resolve,
        // close, reactivate, reopen, new

        // on initial page load, sCommand will be 'load'
        // on viewing a case after canceling an AJAXy action, e.g.
        // canceling an edit, sCommand will be 'view'
        // on page load of the new case page, sCommand will be 'new'

        // run after a delay (in milliseconds)
        setTimeout(doSomeStuff, 100);
    };

    var doSomeStuff = function() {
        // do your work here
    }

    if ($('#sEventEdit').length > 0)
    {
        myFunction('new');
    }
    else if ($('#sEventReply').length > 0)
    {
        myFunction('reply');
    }
    else if ($('#sEventForward').length > 0)
    {
        myFunction('forward');
    }
    else {
        myFunction('load');
    }

    // run it when the view changes and pass in the new view:
    $(window).on('BugViewChange', function(e, data) {
        myFunction(data.sCommand); 
    });

});