New Developer Scripting Powers in xTuple ERP 4.8.0

The release of xTuple ERP 4.8.0 brings with it an exciting feature that should open up new possibilities for those of you writing your own custom scripts. As some of you may know, Qt handles the firing of events and the reaction to those events using the concept of Signals (events), and Slots (event receivers). This allows us to do things such as refresh the list of open sales orders from elsewhere in the application, or to know when a bill of materials has been modified. The one limitation, however, is that these signals can only be defined within the compiled C++ code -- something that the scripting environment cannot do. With this code commit you now have the ability to fire off your own signals from your scripts. Three generic signals have been added to the C++ code that provide an interface for scripts to emit signals that can be tagged with a custom source of the signal, as well as the actual payload you want to convey (such as sending over a text string, a boolean value or an integer).

Let's walk through a simple example:

First, create a new screen under System > Design > Screens, call it signalTest. Make sure the checkbox for Enabled is checked, and then click Edit. We really only need the query button so feel free to delete the rest of the controls from the form. You should wind up with a screen that looks like this:

Save the ui form into the database. On the screen information page, click new script, and enter in the following code:

var _query = mywindow.findChild("_query");
 
// this function is what will act upon the signal once it is fired
// note it is checking the source of the signal, because we only
// care about signals coming from the source "signalTest"
function listenForTestSignal(source, message) {
  if (source == "signalTest") {
    QMessageBox.information(mywindow, source, message);
  }
}
 
// this is the function that sends out our test signal when 
// Query is pressed
function sendTestSignal() {
  mainwindow.sEmitSignal("signalTest", "this is a test message");
}
 
// our connection to the query button's Clicked signal
_query.clicked.connect(sendTestSignal);
// our connection to the new scriptable signal added to xTuple
// we are using QString, but there is also:
// emitSignal(QString, int)
// emitSignal(QString, bool)
mainwindow["emitSignal(QString, QString)"].connect(listenForTestSignal);
 

-----

Save the script into the database, and then save the screen. In the list of screens, highlight signalTest and click test. Our window should open up, and when you click the "query" button the "this is a test message" message should appear in a message box. 

 
 

Check out what's coming up next in the xTuple development roadmap.

 

David Beauchamp

Software Implementation Engineer

The primary directive of the Professional Services Team — made up of xTuple staff and the xTuple Partner global community — is to ensure experts are available to assist in the execution of your new system using the established xTuple implementation methodologies and to optimize the benefits of your new enterprise application. As part of the professional services team, David's deep-dive technical and operational knowledge helps xTuple customers maximize the benefits of ERP in their business. A long time xTuple user, David joined the team after implementing PostBooks® at a multi-national manufacturer. A self-described hardware hacker, David spends his free time in the embedded world voiding warranties, contributing to the open source ARM development community and helping automate life using a plethora of connected devices.