Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

X++ element.args().caller() can not get any result

(0) ShareShare
ReportReport
Posted on by 113

hello,gusys, i use element.args().caller()  can  not get the object .but  in  ax2009  i  can  get result .could you tell  me  why?  pastedimage1680160127722v1.png

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ element.args().caller() can not get any result

    if  i  defined  the  custAccount  with  out  static keyword ,i  can  not  get  value ,but  if  i  use  static  key word  i can get , pastedimage1680165775189v1.png

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: X++ element.args().caller() can not get any result

    What code you should write depends on what want to achieve. Unfortunately, you told us nothing about it, therefore we can't give you any concrete solution.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: X++ element.args().caller() can not get any result

    You can use new method to instantiate object for the class. But check whether you are able to get customer account value.

    Thanks,

    Girish S.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ element.args().caller() can not get any result

    so  you  means   the  best  way  is  use   new()?

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: X++ element.args().caller() can not get any result

    Static method doesn't need any object reference to call. You can directly use scope resolution operator to call the static method. Like ClassName::MethodName();

    Also, you are showing the screenshot for the class, But the error is throwing at form level where you didn't get a caller object.

    Thanks,

    Girish S.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ element.args().caller() can not get any result

    pastedimage1680164833762v1.pngthe  first  picture   i  defined  without  static  .the  second  picture i  defined  with  static   ,now  the custaccount  have  value pastedimage1680164980541v2.png

  • Martin Dráb Profile Picture
    Martin Dráb 230,962 Most Valuable Professional on at
    RE: X++ element.args().caller() can not get any result

    You're wrong in thinking that element.args().caller() always returns a value. It returns an object set as the caller when opening the current form. It's often empty, e.g. when you open a form from main menu.

    The caller is set automatically when a form or a class is opened from through a menu item button on a form and it might (but doesn't have to) be set when a form is opened from code.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ element.args().caller() can not get any result

    ok,but  in ax2009  i can use  element.args().caller().however ,i use new(),the custAcoount can not  get  value  ,System  tell m e  i  need  to  use   static   to define   custAccount

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: X++ element.args().caller() can not get any result

    If you want to init the myBatch object dont use element.args().caller() - This will return the object that is called from.

    If you want to initialize myBatch class, use new keyword to create object for the class, but you won't get customer account as per your scenario.

    Thanks,

    Girish S.

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: X++ element.args().caller() can not get any result

    yes ,but  why  we  can  init  the myBatch object?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans