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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

My event handler showing message twice

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

I've got an issue whereby I want to put 1 field in my form to be mandatory, and if it is empty, it will throw error. So this is the class looks like ->


class CustTableForm_MyField_OnModified

{

 [FormDataFieldEventHandler(formDataFieldStr(CustTable, CustTable, MyField), FormDataFieldEventType::Modified)]

public static void MyField_OnModified(FormDataObject sender, FormDataFieldEventArgs e)

{

FormDataSource custTable_ds = sender.datasource();

CustTable custTable = custTable_ds.cursor();

if (CustTable.Group == "Group1" && CustTable.MyField == NoYes::Yes)

{

custTable_ds.object(fieldNum(CustTable, MyField2)).mandatory(true);

custTable_ds.object(fieldNum(CustTable, MyField3)).setValue("Sample1");

}

else

{

custTable_ds.object(fieldNum(CustTable, MyField2)).mandatory(false);

custTable_ds.object(fieldNum(CustTable, MyField3)).setValue("Sample2");

}

 custTable_ds.refresh();

 

}

}


When I hit Save on my form, while it is empty for Field2, it will show error "Field2 must be filled in" twice. The question is why two times ? Also actually how is the behaviour of this event handler ? because when it is error like that, I cannot even "Esc", it will still in this form until it is satisfied.

For the double message, at first I thought is because the Refresh datasource at below it. it turns out no after I remarks it, the message will still appeared twice.


Please advice,


Thanks

I have the same question (0)
  • Blue Wang Profile Picture
    on at

    Hi WWwong,

    Have you overriden the validateWrite()?

    Debug it , if it return twice.

  • Community Member Profile Picture
    on at

    Hi Blue,

    Debug not showing anything in CallStack. Of course during changing MyField, it will goes to my class and go through my code, but that;s all since it only put mandatory setting.

    ValidateWrite in the table as I tried to run "Find event handlers" was none. It is extension table, but I look for two methods: ValidateWrite and ValidateFields, no eventhandlers for that method.

    What is the best way to trace it anyway ?

    thanks,

  • Blue Wang Profile Picture
    on at

    Hi WWwong,

    It's similar to this: community.dynamics.com/.../542311

  • Community Member Profile Picture
    on at

    Hi Blue,

    The case is similar but the way of doing it is different. What Martin said is right about ValidateWrite thing, and in my case, that's why I don't want to interfere or modify anything in ValidateWrite. I want to leave the checking whether any mandatory field left empty in AX standard.

    What I modified (create) is by adding the setting of make one field to be mandatory, which on that Editing moment is working. What is not correct is while saving and this field I put as mandatory still empty, the error message appeared  twice, like they want to save this record twice.

    Btw, I also tried to put break point in class Info method Add. In hope that I can look at stack trace of the Saving procedure it self, because that is the problem comes from, but this break point not working, coz it didn't stop.

    Btw, in topic u share to me, the issue not solved, right? regarding the "display twice"

    Please advice.

    Thanks.

  • Sukrut Parab Profile Picture
    71,710 Moderator on at

    Did you mark Myfield2 mandatory at table level as well ?

  • Community Member Profile Picture
    on at

    Hi Sukrut,

    No, its not. I want to make the mandatory flexible, that's why I'm using Event Handler to make it mandatory or not at run time.

    Thanks,

  • Sukrut Parab Profile Picture
    71,710 Moderator on at

    Comment your code from the event handler and then see if you get the same messages twice or once. You might have implemented event handler somewhere else as well ?

    Another thing to look at  is, may be your event handler is getting called twice.

  • Community Member Profile Picture
    on at

    Hi Sukrut,

    I commented my event handler then the error message is gone. So it is confirmed that it is my event handler "caused" the error message to triggered.

    But as I post in the topic, the event handler only to set the fields to be mandatory. There is no checking or throw error if the fields is empty in that event handler. I personally think that even if my class is called twice (which is during debug is not) it is not directly triggered the message.

    As counter to my 1st statement here, the event handler "caused" it because it "started"  the setting, but to throw that error is standard behaviour of Ax when checking whether there is some fields that marked as Mandatory still left empty or not, right? It's just like you tell some one to work, but another person will check whether the work is done or not, right ? you can tell many times, but the "checker" will only need to check one time.

    That's is why I tried to debug the Save process as well, but no break at the moment.

    Thanks,

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans