xTuple.com xTupleU Blog & News Customer Support

Can't find ID for Selected Sales Order

I am trying to display a QMessage box when a sales order is opened from the Open Order List.  I have the message displaying but am not able to find the cohead_id to include in my query.  I have created this as salesOrder.js.  I have tried referencing the _list object from openSalesOrder but the _list.id() is -1.  Any ideas on how to find the cohead_id for the following script?

salesOrder.js

 

debugger;

 

var _list = mywindow.findChild("_list");

 

var qry = toolbox.executeQuery("SELECT COALESCE(count(wavebatch_id),0) AS _onwave FROM _wms.wavebatch JOIN cohead ON wavebatch_sales_order_number = cohead_number WHERE cohead_id = "

+ _list.id()

+ ";");

 

var onwave = qry.first("_onwave");

 

if(onwave > 0)

QMessageBox.warning(mywindow, qsTr("WARNING"), "This Sales Order is on a WAVE and should not be updated without permission from the MSC.");

Hi Dave,

What would be an equivalent to the code above to get the Item ID from the Item screen in an Item script?

I have tried the code above but it is not returning the expected value.

Thanks,

Bernard Le Jour

AS Plus Informatique Inc.

you can get the id of the current sales order with mywindow.id();, like:

var cohead_id = mywindow.id();

Also, there is a Qt signal on that screen called newId(int), which will fire off whenever the window has a new id. 

Thanks.  I tried this and the value is -1 at the time the script runs.  I can see that the ID is being passed from openSalesOrder.cpp to salesOrder.cpp as a parameter.  How do I intercept it?

The salesOrder window has a newId(int) signal that you can use to capture the id:

function sHandleNewId(newid) {

  // do something with newid

}

mywindow["newId(int)"].connect(sHandleNewId);

Once inside the sHandleNewId function, the newid variable will hold the id that the window just loaded/created. Note that this fire when you open a salesOrder, but also once the window clears when you save it, in which case it will give you -1 for the id if there isn't one set. Just make sure to check for -1 before acting --

 

Are you getting an error? The item screen has the same signal, newId(int), defined here https://github.com/xtuple/qt-client/blob/4_10_x/guiclient/item.h#L102 which means the same signal fire, inside the sHandleNewId function does newId not hold the id of the item being edited?

Hi David,

There was indeed an error that prevented the script to complete. We have corrected the error and now we get the right value.

Thanks,

Bernard Le Jour

AS Plus Informatique Inc.

Thank you for your help.  Here is what the final script looks like.  (updated with script that works.)

//debugger;
 
mywindow["newId(int)"].connect(sHandleNewId);
 
function sHandleNewId(newId)
{
if (newId == -1)
{
return;
}
var _coheadid = newId;
 
var qry = toolbox.executeQuery("SELECT COALESCE(count(wavebatch_id),0) AS _onwave FROM _wms.wavebatch JOIN cohead ON wavebatch_sales_order_number = cohead_number WHERE cohead_id = "
+ _coheadid + ";");
 
if (!qry.first())
{
QMessageBox.warning(mywindow,qsTr("WARNING"), "Query returned no results");
        return;
}
var onwave = qry.value("_onwave");
if(onwave > 0)
QMessageBox.warning(mywindow, qsTr("WARNING"), "This Sales Order is on a WAVE and should NOT be MODIFIED without permission from the MSC.");
}