web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Problem with updating table field by selecting a value from a dialog form.

(0) ShareShare
ReportReport
Posted on by 845

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?

I have the same question (0)
  • Martin Dráb Profile Picture
    239,176 Most Valuable Professional on at

    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.

  • Shooowtek Profile Picture
    845 on at

    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.

  • Shooowtek Profile Picture
    845 on at

    Of course I meant DataEventType::Updating. Sorry about that.

  • Martin Dráb Profile Picture
    239,176 Most Valuable Professional on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 681

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 446 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 202 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans