Open filtered forms with X++

When using forms in Dynamics AX we usually get access to them by clicking a button that uses a menu item, this along with the args that is sent we get a form that displays the requested information. But if you want to do this using code, how is this done?

You usually see this used in classes such as SalesFormLetter or PurchFormLetter that uses an existing form instead of a creating a temporary one. The user enters the information and the class uses the new information to perform the tasks at hand.

This is a pretty simple job that first displays a filtered CustTable form for the customer “4004”, when this form is closed the CustTrans form will be opened and display the relevant data of the customer we are using. As this is done you will also see that it’s possible to either halt the code while a form is open or simply detach it and let the code continue.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
static void FO_OpenFilteredForms(Args _args)
{
    Args    argsCust, argsTrans;
    FormRun formRun, formRun2;
    CustTable custTable = CustTable::find("4004");
    ;
 
    argsCust = new Args(formStr(CustTable));
    argsCust.record(custTable);
 
    formRun = classFactory.formRunClass(argsCust);
    formRun.init();
    formRun.run();
    formRun.wait();
 
    print "This should be printed when " +
          "the CustTable form is closed.";
    pause;
 
    argsTrans = new Args(formStr(CustTrans));
    argsTrans.record(custTable);
 
    formRun2 = classFactory.formRunClass(argsTrans);
    formRun2.init();
    formRun2.run();
    formRun2.detach();
 
    print "This should be printed as " + 
          "the CustTrans form opens.";
    pause;
 
}

Last 5 posts in Development

Leave a Reply

Your email address will not be published. Required fields are marked *