Hello,
There is a requirement that specifies that when the user changes a value in the X fields, he should specify the reason for the change.
The X field is a standard field in SalesTable. I wrote the following code that, after changing the value of the field, displays a dialog form for the user to select the reason for changing the X field. The selected reason is saved in an additional field in the table.
1 I extended the update() method in SalesTable
public void update() { SalesTable salesTable_orig = this.orig(); next update(); if(this.Field_X != SalesTable_orig.Field_X) { this.runDialogToChangeReason(this.SalesId); } }
2. The runDialogToChangeReason method, with _salesId as an argument
public void runDialogToChangeReason(SalesId _salesId) { Dialog dlg; DialogField dfg; dlg = new Dialog(); dfg = dlg.addField(EnumStr(ChangeReason), "Reason"); if(dlg.run()) { salesTable::setChangeReason(_salesid, dfg.value()); } }
3. The setChangeReason method, with _salesId and _reason as an arguments
public static void setChangeReason(SalesId _salesId, ChangeReason _reason) { SalesTable salesTable = SalesTable::find(_salesId); ttsbegin; salesTable.selectForUpdate(true); salesTable.ReasonField = _reason; salesTable.update(); ttscommit; }
When selecting a value in the dialog and attempting to save, I always get the error "An unbalanced x TTSBEGIN/TTSCOMMIT pair..."
I tried debugging, but when starting the dialog, I immediately get the aforementioned error....
I also tried to insert ttsabort but also without success....
if (appl.ttsLevel() != 0) { ttsabort; }
Could I have your help please?
Both of your suggestions still mean calling your code from update() and therefore you'd still have the identical problem.
Are you sure you need a dialog at all? Can't users simply set the value of ReasonField? Then you'll just validate (in validateWrite()) that it has a value.
Of course I meant DataEventType::Updating. Sorry about that.
Thank you Martin for your reply. It explains a lot.
So in my case, where is the best place to do it? Is it before calling next metod or using DataEventType::Inserting?
I need to display a dialog after the user changes the value in the X field.
Thank you in advance for your suggestions.
There is a design flaw in your solution.
update() will be called in a transaction and if you opened a dialog there, the transaction could stay open for a long time or even forever, and all locks obtained in the transaction could be blocking the system for a long time (or forever). As a last resort to prevent this potentially catastrophic situation, the transaction is aborted when the dialog is opening.
You need to this work before starting the transaction.
André Arnaud de Cal...
292,160
Super User 2025 Season 1
Martin Dráb
230,962
Most Valuable Professional
nmaenpaa
101,156