A while ago I created a grid application using ScriptCase to list all not-completed orders, and because each order could have different status, I added a column to show an image/icon based on its status:

ScriptCase - Grid application with images/icons

In the onRecord event I checked the status and set the content of that column - an IMG tag, i.e., plain HTML - and everything worked fine, except when exporting that grid to XLS (or PDF).

When exported to XLS using ScriptCase’s exporting option, the status column showed just an empty cell - and no images at all. Besides not working as expected, that image/icon wasn’t really desired inside the XLS file and for this case a simple text would be much better: it would allow the status to be used in formulas, functions, searches, etc.

To this day, ScriptCase (latest is v9.0.029) doesn’t provide any macro or documented steps to check if onRecord event is running for a “normal grid webpage” or for an exportation. With that in mind, I had to find out for myself a way to present a different content for that column when exporting to XLS.

After some time analysing the code generated by ScriptCase I found out how to detect what triggered the onRecord event - and it also works for PDF, CSV, XML and RTF.


For better or for worse, ScriptCase is heavily dependant on PHP’s $_SESSION global, using it to store a lot (and I mean it!) of information: general and database settings, states of applications, dictionary of (language) strings, errors status, and even HTML content for things such as buttons. And, as I said, ScriptCase also uses $_SESSION to store the state of the applications.

When executed inside the events of a grid (e.g., onRecord), the code below shows where ScriptCase stores what process is currently running - whether it’s the normal grid webpage, or the exportation to PDF, XLS, CSV, etc:

$runningProcess = $_SESSION["sc_session"][$this->Ini->sc_page][$this->Ini->nm_cod_apl]["opcao"];
echo $runningProcess; // this may print "XLS", PDF", "CSV", etc

Note: Although “opcao” is a Portuguese word (which means “option”), for this code to work, it should be exactly like that!

And then to present a different content/value for a column when exporting to XLS, I did this:

$runningProcess = strToLower($_SESSION["sc_session"][$this->Ini->sc_page][$this->Ini->nm_cod_apl]["opcao"]);

if($runningProcess == "xls"){ // check for xls, but it can be pdf, csv, etc
	// change the {Status} column to a simple text...
	{Status} = "?";
	// change the {Status} column to be an img (<img src=...)
	{Status} = "<img src='?.png' height='16'/>";

And that was all.