xTuple.com xTupleU Blog & News Customer Support

Scripting Against "Private" Characteristics

Goal: Utilize the Lot Serial Characteristics via scripting on the createLotSerial Screen

Previously before Lot Serial Characteristics were in the core package, I was able to access the field information (text, date, etc) and farther manipulate the on screen widgets… Now I cannot . I have searched the CPP and they are apparently hidden.

I was hoping to get something from _charWidgets or even searching through the layout for a reference any of the LS Char fields… Can any one give me a hint on how to accomplish this?

Example… One characteristic is a production date. I would like for the user to enter the production date and script the calculated expiration date… Or vice versa. Another thing I am doing is repopulating the characteristic fields with the same information until the item changes or the post is complete.

Thanks in advance.

I had a moment to look at this and found a brute force way to get at the characteristics on this screen, but with some caveats. While you can get access to the widgets that are added dynamically the objectName property on these widgets is not set, meaning you can only identify them by their class, so if you got a DLineEdit for a date or an XLineEdit for the text boxes and XComboBox for combo boxes. If you only had one of each you could get away with it as is, but if you have more than one of each you wouldn’t be able to tell which combo box was for which characteristic, for instance.

Here is the code, create a script called createLotSerial:

var _grid = mywindow.findChild("gridLayout");
var widgets = {};
var widgetCount = 0;

for (var i = 0; i < _grid.rowCount(); i += 1) {
  for (var c = 0; c < _grid.columnCount(); c += 1) {
    var li = _grid.itemAtPosition(i,c);
    if (li && li.widget()) {
      widgets[widgetCount] = li.widget();
      widgetCount += 1;
    }
  }
}

debugger; // now widgets has all the widgets from the grid

However as I mentioned before there is no direct way to know what characteristic the widget represents. You may be able to get away with assuming if there are a common set of characteristics but that could get messy quick if you have different characteristics for different items.

All is not lost, please file a feature request to make LotSerialUtils set the objectName property on the widgets when it adds them to the grid here: https://github.com/xtuple/qt-client/blob/4_11_x/guiclient/lotSerialUtils.cpp#L156-L209. If we set the objectName to be the name of the characteristic it would be simple to retrieve from the window with mywindow.findChild() instead of having to do the witch hunt like above.

1 Like

Nice R&D Mr Beauchamp!

Looks simple enough to add the objectName to this area of the application.