Customize the 8.0 Notes/History grid
Posted By: nicocrm on November 11th, 2013 in General
No Gravatar

Customizing the notes/history grid on Saleslogix 8.0 is similar to customizing the activity dialog – the relevant function has to be overridden via a separate Javascript file. Like the activity customization, this allows for a no-touch upgrade since the stock file does not have to be modified.

First of all, let’s start with the simplest of customizations – displaying the tab on a new entity. This is actually just a matter of adding the smart part to your page definition, and making sure there is a property define on the Activity (and History – they both go hand in hand) entities to represent the relationship with a name matching the table with an “Id” extension (for example “SalesOrderId” for the SalesOrder). Note that even if you only want to add the Notes/History tab to the module you must add the property to the activity entity, and the name on the activity entity has to match the name on the history entity (case and all) – this is due to a quirk of the NotesHistoryList form which checks the Activity properties instead of History. Also, the property needs to match the physical table name of the entity being linked to – including underscore if present (that one is not case sensitive though).

Adding a column to the form requires a bit more work. A little bit of digging in the NotesHistoryList.ascx.cs file shows that the grid is built by a custom class named Sage.UI.NotesHistoryList. This class is defined in the Sage.js file which is not directly editable (this is a combined javascript file, even though in theory it would be possible to make changes to it, it would be extremely tedious to do so, and it would make all upgrades more complicated). Fortunately the Swiftpage developers provided us with an extension point that can be used to inject custom functionality in the grid without having the need to modify the file directly: the method at NotesHistoryList.onBeforeCreateGrid. We can use dojo.aspect to seamlessly inject our functionality there in a way that will not even impact other custom modules that extend the grid:

require(['dojo/aspect', 'dojo/ready'], function(aspect, ready) {
  ready(function() {
    if(Sage.UI.NotesHistoryList) {
      aspect.before(Sage.UI.NotesHistoryList.prototype, "onBeforeCreateGrid", function(options) {
        // here we can modify options.columns to include our custom column
      });
    }
  });
});

To add a column for “SalesOrderName” for example (which is a custom property I added to the History entity):

// ...
var colConfig = {
    field: 'SalesOrderName',
    name: 'SO #',
    width: '200px',
    // note "textFilter" is an alias for Sage.UI.SLXPreviewGrid.Filter.Text (see complete code below)
    // you can leave this out if you don't need the new field to show in the filter
    filterConfig: { widgetType: textFilter }
};
// of course instead of push you can use splice to insert the new column at your chosen point and remove columns you don't want
options.columns.push(colConfig);
// ...

The complete Javascript code looks like this:

require(['dojo/ready', 'dojo/aspect', 'Sage/UI/SLXPreviewGrid/Filter/Text'], function (ready, aspect, textFilter) {
    ready(function () {
        if (Sage.UI.NotesHistoryList) {
            aspect.before(Sage.UI.NotesHistoryList.prototype, "onBeforeCreateGrid", function (options) {
                var colConfig = {
                    field: 'SalesOrderName',
                    name: 'SO #',
                    width: '200px',
                    filterConfig: { widgetType: textFilter }
                };
                options.columns.push(colConfig);
            });
        }
    });
});

To load it in the client, ideally you would create a module and use ScriptManager.RegisterStartupScriptBlock. This will make it completely non-invasive and (provided Swiftpage does not change the API for the grid) upgrade safe. But in a pinch you can also add it to base.master – in that case of course it’s not upgrade safe.


Leave a Reply