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

How to know at coc of doapply() of a form class if ok() was clicked

(0) ShareShare
ReportReport
Posted on by

Hello ,

I have coc in form class at doapply(). I have noticed in debugger that the doapply() is called when user clicks on ok button of the form. Please share what x++ code at doapply() coc can evaluate if doapply() is being called via click ok button

Regards,

Mav  

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

                

  • André Arnaud de Calavon Profile Picture
    301,075 Super User 2025 Season 2 on at

    Hi Mav,

    Can you explain the business requirement? What exactly would be the goal of your customization?

    Do you think of an extension class and use COC on closedCancel or closedOK?

    Note that volunteers are monitoring this forum and do answer the questions in their spare time. For that reason, an additional remark about urgency is of no use.

  • Mav Profile Picture
    on at

    I have updated the thread .

    Please share what x++ code at doappy() coc of form can help in determining if doapply() was called after user clicked on ok button.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Please tell us what business requirement you're trying to address. It's not clear why you're using doApply() - and whether you should be doing it at all. We also know nothing about the button, e.g. whether it's a command button or what.

    We can't help you if you don't give us enough information about your situation.

  • Mav Profile Picture
    on at

    Hello Martin.

    Apply and Ok are command button. I am referring to InventMarking form.

    Business req is to run a custom code let us say its info("Hello custom code") when user clicks on Ok or apply.

    For this COC was done on closeok() and doApply() method of the form and Info ("Hello custom code") was added in both COC.

    During debugging it was notice that doApply() is called even when you click only Ok at form.

    This is causing ("Helo custom code") to appear twice, 1 from COC of closeok() and other from doApply()

    So I removed info("Hello custom code") from closeok() .

    Now when user clicks on Apply I get  info("Hello custom code") and then when user clicks on Ok I again get info("Hello custom code")

    Hence need is to validate at COC of doAppply () if apply has been clicked before ok, if yes then do not run custom code nfo("Hello custom code").

    Thanks

    Mav

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Yes, doApply() is called after closing. My understanding is that Apply button is for applying without closing and OK is for applying and closing.

    It sounds to me that you simply shouldn't be calling the same logic in closeOk(), because doApply() handles both of your cases.

    If there was a legimitate case to distinguish whether doApply() was called from OK button, closedOk() method could help.

  • Mav Profile Picture
    on at

    There is a genuine case like shared in my previous  post which is that custom code at doapply() should only trigger twice .

    Curgent issue is that I have custom code say info (“hello world at doapply”) in do apply().

    so when user clicks doapply() I see the above info which is fine , how ever when user clicks ok after apply , I see 2 info hello world , req is that there should be only 1 info of hello world .

    can you please share code or point in correct direction .

    Thanks

    Mav

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Changes may be applied several times. For example: I make changes, press Apply, do some other changes, press Apply, do more changes, press OK. It means that changes were applied three times and if you put info() to doApply(), you'll see the message three times. (Four times with your current logic, because you add the same message once more in closeOk()).

    If you don't like this result, you need to think about what logic you actually want (based on the business requirements, which are unknown to us). For example, you could show the message just for the first time and then skip it when changes are applied again.

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
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans