Changing SData grid’s layout at runtime?
Posted By: nicocrm on June 26th, 2014 in Saleslogix
No Gravatar

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).

Unit Testing SLX – 8.1 Update, and OpenSlx
Posted By: nicocrm on June 15th, 2014 in General
No Gravatar

Unit Testing Saleslogix is possible and easy to set up with the recent improvements to the OpenSlx library. The SlxAppSetup class is what you need to initialize the Saleslogix framework and enable you to use EntityFactory, SessionScopeWrapper etc from the Saleslogix libraries. Very useful for automatically validating changes to your custom code, and also when you are trying to figure out the syntax for an NHibernate query without having to restart SlxClient over and over.

This is what you need to start testing your business rules using NUnit:

  1. Download and compile OpenSlx from github. You’ll probably need to adjust the references to point to a deployed Saleslogix site.
  2. Download NUnit, I also recommend TestDriven.Net for running tests easily from Visual Studio, make sure you use the last version of both tools. Note that I was not able to run them using the regular NUnit test runner, probably due to the way the reference assemblies are getting copied as part of the test run.
  3. Create your unit test assembly in Visual Studio. Add a reference to your business rules assembly, NUnit, OpenSlx, and some Saleslogix libraries (which can be found on a deployed Saleslogix site). You’ll also want a reference to your custom Sage.Entity.Interfaces.dll which is under the Model\deployment folder. One tricky part here is you do need references to the correct SLX libraries or the test suite setup will fail and the message in the Visual Studio test runner will not be extremely useful (you can get a better message by testing with the debugger, though)
  4. If you are doing business rules using code snippets, you have to add a reference to that project, located somewhere under your Saleslogix build path.
  5. Create a TestSuiteSetup class. This needs to be in the same namespace as your unit test, this way its Setup and Teardown methods will run before and after each of your tests respectively.
  6. You can now right click to run your unit tests from within Visual Studio:
    Testdriven Menu

I uploaded a sample test project. Feel free to use it as a base, just adjust the references to match your environment.