Problem: you have an editable grid with a column that needs to display a custom caption according to some properties of the current entity.

Solution: on a custom smart part you control the javascript so this can be easily addressed by using the client context service. On a quickform you need to modify the grid on the fly, and there is no injection point within the script itself (ideally Swiftpage should give a way to inject custom javascript inside of the “makeGrid” method, like they do for the attachment tab). A bit of hacking with dojo.aspect and setTimeout lets you manipulate the grid’s structure right after it is created, though:

String gstName = SSSWorld.ISCO.BusinessRules.CTaxRateRules.GetGSTName(order.Company);
String script = @"require(['dojo/ready', 'dojo/aspect', ],
function(ready, aspect) {
ready(function() { 

aspect.after(Sage.UI.Forms.BarrelOrderDetails, 'makeGrid', 
function() { 
var fnFormatGrid = function() {
	var grid = dijit.byId('BarrelOrderDetailsgrdBarrelOrderDetails');
        setTimeout(fnFormatGrid, 100);
	var structure = grid.structure;
	for(var i=0; i < structure[0].cells.length; i++){
		var cell = structure[0].cells[i];
		if(cell.field == 'GSTAmount'){

if (String.IsNullOrEmpty(gstName))
    // remove GST column
    script += "cell.hidden = true;";
    script += " = '" + gstName + "';";
script += @"} // if
} // for
}  // fnFormatGrid

}); // aspect.after
}); // ready
}); // require
ScriptManager.RegisterStartupScript(this, GetType(), "GSTColumnFormat",
    script, true);

Putting this in a load action on the form will make that code invoked after the accompanying JS file is loaded which gives you access to the specific class (in the Sage.UI.Forms namespace) used to initialize the grid. You still need a setTimeout because the grid will not be instantiated immediately (it is itself inside of a require() call).

Share This