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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to write the form methods logic in class method?

(0) ShareShare
ReportReport
Posted on by 931

Hi all,

I have two forms A and B,

In Form A i have stringedit control and a button to filter the grid. and i have a mouseDblClk to pass the record to Form B.

Everything works fine when i use the codes in form.But, I need the logic in a class.

help me with codes that i have to write in class methods. i used the same codes i used in form ovveride methods, it doesn't work.

for instance when i doubleclick the grid the record have to pass to form B, for that i use mouseDblClk method. and it works perfectly, if i use the same code in a new class method and in the mouseDblClk method i called class method, it doesn't work.
 Pls Help!

*This post is locked for comments

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

    First of all, show us your code in mouseDblClk() - we can't discuss unknown code. Then please elaborate why are you using mouseDblClk() at all - it's very unusual and therefore possibly wrong. I suggest you either use a default action of the grid, or you use a normal button. If you use a button, you still can get information about the selected record(s); you don't have to override grid's methods for that.

  • ThivaKar Profile Picture
    931 on at

    Hi martin,

    this is my code

    ==============================

    public int mouseDblClick(int _x, int _y, int _button, boolean _Ctrl, boolean _Shift)

    {

       int ret;

       Args args;

       FormRun formRun;

       ret = super(_x, _y, _button, _Ctrl, _Shift);

       args = new args(formstr(Form B));

       args.record(MyTable);

       formrun = classfactory.formrunclass(args);

       formrun.init();

       formrun.run();

       formrun.wait();

       formrun.detach();

    }

    and for your question that why i am using mouseDblClk() i have no answer for that..

    All i wanted to do is to open the new form to view the details of that record. i can achieve it in button or anyother. but i want that in my double click event.

  • Suggested answer
    Martin Dráb Profile Picture
    238,208 Most Valuable Professional on at

    Don't bother writing code for opening a form - simply create a menu item (pointing to FormB) and drag it to FormA. You may also need to set the DataSource property of the menu item button, but you don't need even a single line of code.

    You could also invoke the button from code, if you had a strong reason to do it.

  • ThivaKar Profile Picture
    931 on at

    Thanks martin.

    Appreciate that.

    All i wanted to know that why that code of mine is not working in class and if i need to work that in my class? what modification should i do?

    I cant do it as u say (menu item). Because my requirement is to make my code work in class.

    and that code is just a sample code. And i am trying to learn how to use the form methods

    in classes and just calling the methods of class in my form

  • Suggested answer
    Martin Dráb Profile Picture
    238,208 Most Valuable Professional on at

    Your other thread shows that you assume that if a variable exists in one class (such as your form), it will also exist in other classes, which is completely wrong.

    Your can just copy code form one class and put it into another, because different classes have different variables and methods. That's the answer to your question "Why that code of mine is not working in class?".

    You'll have to update your code to work in the different context. If you want to use references to objects available in the form, you'll have to get those references to your class.

  • ThivaKar Profile Picture
    931 on at

    Yeah , exactly martin.

    Thats why i mentioned what modification i have to do it in my class method?

    Please send example code to write in my class for the above form method code

  • Martin Dráb Profile Picture
    238,208 Most Valuable Professional on at

    You really should spend more time learning basics, such as how to use variables, method and objects. This problem has little to do with forms and Dynamics AX.

    Your code depends on a variable called MyTable - if you don't have it in your class/method, you'll get a pretty clear compilation error.

    You have many ways how to get the reference in your class. One is simply passing the variable to your method. First of all, you add a parameter to you method, such as:

    public void openForm(MyTable _myTable)

    Then you can use _myTable variable in your code.

    When you call the method from your form (or any other code), you'll provide the parameter. If you have MyTable variable in your form, you can use that:

    myClass.openForm(MyTable);

    Nevertheless don't use your code to open forms - create a menu item instead and then call it in some way like this:

    Args args = new Args();
    args.record(_myTable);
    
    menuFunction = new MenuFunction(menuitemDisplayStr(FormB), MenuItemType::Display);
    
    if (menuFunction.checkAccessRights())
    {
        menuFunction.run(args);
    }

     But you really should realize that you don't need any code at all to open a form. And the best code is no code, because you don't have to write, you don't have to maintain it and you can't have any bugs in it.

  • ThivaKar Profile Picture
    931 on at

    I have created a menuitem like you said .

    it opens the form B , but the selected record is not showing in form B.

  • Martin Dráb Profile Picture
    238,208 Most Valuable Professional on at

    If something doesn't work, debug it. First of all, check whether you're passing the right record. If not, the problem is on the calling side. If you do, the problem is in the called form.

    If you need some help for us, please tell us how you're using the menu item. Please don't forget that we don't see your system, therefore you have to write everything down here.

  • ThivaKar Profile Picture
    931 on at

    My class method

    ======================================================

    public void newfrm(MyTable _myTable)

    {

       Args args =new Args();

       args.record(_myTable);

       new MenuFunction(MenuItemDisplayStr(Form B),MenuItemType::Display).run(args);

    }

    this opens the Form B.

    My problem is that only 1st record gets passed in form b.

    so i have to use init method of form B,

    How can i get the passed record (_myTable) in my form B init method??

    ==============================================

    If i use like this ---->

    public void init()

    {

       MyTable _myTable;

       super();

      _myTable= element.args().record();

       MyTable _ds.query().dataSourceTable(Tablenum(MyTable )).

       addRange(fieldNum(MyTable ,RecId)).

       value(SysQuery::value(_myTable.RecId));

    {

    <----------

    It gets only the first record in Form B.

    And again How can i get the passed record (_myTable) in my form B init method??

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

News and Announcements

Season of Giving Solutions is Here!

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
TAHER Mehdi Profile Picture

TAHER Mehdi 3

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#2
Nakul Profile Picture

Nakul 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans