Hi! For some time (over 3 years), we’ve been using a bit of code which helps us number our clients’ Invoice ID’s, Inventory ID’s etc.
We’ve been moving our code to Servoy 6.
In the development environment we have, this code works nicely.
In the production environment, we cannot acquire the lock, and there for, the method hangs.
Both environments are using MySQL
The production environment on Servoy 4 uses the same code on the same MySQL db, and it works.
Any ideas why after changing to Servoy 6, it hangs?
function getInvoiceID(event, arg0, arg1)
{
//search on the form (lets call it Customers) and find that customer
var customerID = arg0 //arguments[0]
var transtype = arg1 //arguments[1]
var frm = 'cji_frm_customer_accounts'
var fld;
if (transtype == 'S')
{
fld = 'last_invoice_id'
}
else if (transtype == 'P')
{
fld = 'last_po_id'
}
else if (transtype == 'A')
{
fld = 'last_adj_id'
}
else if (transtype == 'T')
{
fld = 'last_trans_id'
}
else if (transtype == 'C')
{
fld = 'last_credit_id'
}
if (forms[frm].controller.find())
{
forms[frm].cji_customer_id = customerID
var count = forms[frm].controller.search()
var fs = forms[frm].foundset
var lockCount = 0
if(count == 1) //customer record was found
{
var success = false
while(!success) //loop until we can get the record
{
success = databaseManager.acquireLock(fs,0,fld) <--- fails right here... success comes back as a false
if(success)
{
databaseManager.refreshRecordFromDatabase(forms[frm].foundset, 1)
forms[frm].last_invoice_id = forms[frm].last_invoice_id + 1 //assuming lastInvoiceID is your column name
if (!forms[frm][fld]) {forms[frm][fld] = '1000'} // if there is no number, we start with a default
var setFrm = forms[frm][fld] = forms[frm][fld] + 1 //assuming lastInvoiceID is your column name
var thySave = databaseManager.saveData()
if (!thySave)
{
//var errSave = databaseManager.getLastDatabaseMessage()
var errRecs = databaseManager.getFailedRecords()
databaseManager.rollbackEditedRecords()
//application.setStatusText(errSave);
return false;
}
databaseManager.releaseAllLocks(fld)
return forms[frm][fld] //return the value back
}
else
{
application.sleep(1000) //1000 miliseconds = 1 second
lockCount = lockCount + 1
if (lockCount > 10)
{
globals.setMessagePrompt(event,'Error: There was a problem obtaining the ID from the database. [getInvcoiceID]',4,3)
return false;
}
}
}
}
}
else
return null;
return null;
}