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

When I use View in Form to get selected record on form but it open two form instead of one form[Ax 2012]

(0) ShareShare
ReportReport
Posted on by 256

I have two form. I.e. FormA and FormB. In FormB is attached with a view. [we have used multiple table relations so I use view]

When I select FormA Record on button click then its related data it has shown on FormB. But Problem is that is shown FormB all record views [FormB view is Problem]

So I know that code pass argument one form to another but I didn’t find How is open two form on one click [related record on FormB and FormB View with all Record]. I want to open only one formB with related record 

**FormA Click Method

void clicked()
{
    Args        args;
    FormRun     formRun;
    super();
    args    = new args(formstr( FormB));
    args.parm(HcmWorkerTB.PersonnelNumber);

    
    formRun = classFactory.formRunClass( args );
    formRun.init();
    formrun.run();
    formrun.wait();
    formRun.detach();
}

** FormB Init Method

public void init()
{
        Query           query;
        QueryBuildRange qbr;
       
        Str             _parmid;
        super();
       
        _parmid     = element.args().parm();
        query       = new Query();
        qbr=query.addDataSource(tableNum(ST_BankInfoTableView)).addRange(fieldNum(ST_BankInfoTableView,PersonnelNumber));
        qbr.value(_parmid);
        ST_BankInfoTableView_ds.query(query);
}

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    You are putting your query range in place too early. The query will be reinitialized in the init method of the data source of form b.

    Try removing that code and putting this code in the executeQuery method of your data source:

    QueryBuildDataSource qdbs = this.query().dataSourceName([yourDataSourceName]);
    ;
    qdbs.clearRanges();
    qdbs.addRange(fieldNum(ST_BankInfoTableView,PersonnelNumber)).value(parmId);
    super();


    And obviously you have to introduce the parmId variable in classDeclaration, and set the value for it in the init method of the form.

  • NeoMatrix Profile Picture
    256 on at
    Thanks Nikolaos.

    QueryBuildDataSource qdbs = this.query().dataSourceName([yourDataSourceName]); here which data source name enter formA datasource or FormB.
    In FormB I used View and FormA I used Table.
  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    The data source name of form B. It's the only one that can be accessed there.

    But I'm still not sure if I understand your problem correctly. Did you say that two forms open?

    If that's the case, then your button must be a MenuItemButton.

    If it is a MenuItemButton, then the super() call in the clicked method runs the menu item and opens formB. This FormB is not filtered.

    Then your code in clicked method opens another instance of FormB. This FormB is filtered, if your filtering logic works correctly.

    May I also suggest that you change your code in the clicked method to this (if it's a MenuItemButton):

    void clicked()
    {
        Args         args = new Args();
        MenuFunction menuFunction = this.menuFunction();
    
        args.parm(HcmWorkerTB.PersonnelNumber);
        menuFunction = new MenuFunction(menuitemDisplayStr([NameOfYourMenuItem]), MenuItemType::Display);
    
        menuFunction.run(args);
    }


  • NeoMatrix Profile Picture
    256 on at

    In FormB executeQuery it gives the Error "Argument 'name' is incompatible with the required type."

    public void executeQuery()
    {

    QueryBuildDataSource qdbs = this.query().dataSourceName(ST_BankInfoTableView);  Here It Give Error "Argument 'name' is incompatible with the required type."
    ;
    qdbs.clearRanges();
    qdbs.addRange(fieldNum(ST_BankInfoView,PersonnelNumber)).value(parmId);
    super();

    }

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Use quotation marks.

  • NeoMatrix Profile Picture
    256 on at

    My Task Is that If I select FormA Field [like id]  that's related record it shown on FormB. Its logic I have written on Form it works but it opens two form. which are fromB View [all record]  and selected Record of FormB.

    7774.Scr.png

  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Yes. Did you try my suggestion on modifying the clicked method. That will resolve the issue of two forms opening instead of one.

  • NeoMatrix Profile Picture
    256 on at
    Here Is Final Code
    **FormA :- MenuItem Click Method **
    
    void clicked()
    {
        Args         args = new Args();
        MenuFunction menuFunction = this.menuFunction();
    
        args.parm(HcmWorker.PersonnelNumber);
        menuFunction = new MenuFunction(menuitemDisplayStr(DisplayForm), MenuItemType::Display);
    
        menuFunction.run(args);
    }
    ** FromB :- Init Method **
    
    public void init()
    {
    
        str         parmId;
        parmId     = element.args().parm();
    }
    ** FromB :- DataSource executeQuery method **
    
    public void executeQuery()
    {
    
    QueryBuildDataSource qdbs = this.query().dataSourceName(ST_BankInfoView); // Give Error "Argument 'name' is incompatible with the required type." and Where Put "?" 
    ;
    qdbs.clearRanges();
    qdbs.addRange(fieldNum(ST_BankInfoView,PersonnelNumber)).value(parmId);
    super();
    
    }
    

    How can I solve this Problem?

  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    1) Introduce str parmId in classDeclaration. Otherwise it's not visibile outside init method

    2) I said quotation mark, not question mark. In executeQuery method it should be like this: QueryBuildDataSource qdbs = this.query().dataSourceName('ST_BankInfoView');

  • NeoMatrix Profile Picture
    256 on at

    Thanks. It's Work Perfect.

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

#1
Basit Profile Picture

Basit 1

#1
GL-01081504-0 Profile Picture

GL-01081504-0 1

#1
Roya Profile Picture

Roya 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans