I have field on a form that is a fk back to another table, as such if a user enters a value into the field I want to check to see if it already exists in the child table (I am using natural keys in this case) and if if the record does not exist in the child table yet, I want to present the user with the opportunity to create it.
So I have attached a simple method to the onDataChange to the field that starts out with the following…
var oemCartonID = arguments[1];
var oemCartonFoundSet = databaseManager.getFoundSet(controller.getServerName(), 'oem_carton_dim');
oemCartonFoundSet.find();
oemCartonFoundSet.oem_carton_id = oemCartonID;
oemCartonFoundSet.search();
//we already know about this carton id, so let the user use it and return true
if (databaseManager.hasRecords(oemCartonFoundSet)) {
return true;
}
Now say I have two record in the table (which in fact i do) with the oem_carton_id values of ‘123’ and ‘ABC’. If I put a value such as ‘789’ into the field that has this onDataChange and subsequently calls the above find, the resulting foundset will be both ‘123’ and ‘ABC’ records rather than an empty or null foundset.
However if I use a form to do the search for the same ‘789’ value…
var oemCartonID = arguments[1];
forms.workflow_oem_carton_dim.controller.find();
forms.workflow_oem_carton_dim.oem_carton_dim_id = oemCartonID;
forms.workflow_oem_carton_dim.controller.search();
//we already know about this carton id, so let the user use it and return true
if (databaseManager.hasRecords(forms.workflow_oem_carton_dim.foundset)) {
return true;
}
I will get the expected empty foundset. And the code continues on with the steps to create the record.