Discussion:
How to call a form from a method?
(too old to reply)
Abraham
2005-11-02 16:31:03 UTC
Permalink
Hi all,
Just learning to program in axapta. I can give you the full story if you
wish. The short version is: I need to call a form from a method, pass some
information to and back. The form needs to display a grid of information and
pass back a yes/no field. Have been looking for some examples in the
tutorial area but have not found one. Dose any one now of a (good) example
of how to do something like this?

Thanks
Abraham Z.
Allan Wallis
2005-11-02 19:00:03 UTC
Permalink
Look in the developers guide - search for Activating a menu item from your
X++ code

The text is reproduced below

Activating a menu item from your X++ code
To execute a menu item from your X++ code you use the MenuFunction system
class.

This is illustrated in the example below that is from the LedgerJournalTrans
table. The actual code extract is from the formSettlement method.



Note
Considering the new security system, you should create a menuitem, as
menuitems automatically inherit security settings.



client boolean formSettlement(LedgerJournalEngine _ledgerJournalEngine)

{

FormRun formRun;

Args args = new Args();

boolean end = false;

;



if (!this.accountNum)

{

throw error("@SYS25989");

}



// Generate parameters



args.record(this);

args.parmobject(_ledgerJournalEngine);



// Perform a test on the type journal



switch (this.accountType)

{

case LedgerJournalACType::Cust :



// Case of type journal is customer then open the form Customer open
transactions.



formRun = new MenuFunction(menuItemDisplayStr(CustOpenTrans),
MenuItemType::Display).create(args);

break;

case LedgerJournalACType::Vend :



// Case of type journal is vendor then open the form Vendor open transactions.



formRun = new MenuFunction(menuItemDisplayStr(VendOpenTrans),
MenuItemType::Display).create(args);

break;

default:



// If none of the above the do nothing.



end = true;

}

if (! end)

{

if (formRun)

{



// Run the form and wait until the form is closed.



formRun.run();

formRun.wait();

}

}

return end;

}
Post by Abraham
Hi all,
Just learning to program in axapta. I can give you the full story if you
wish. The short version is: I need to call a form from a method, pass some
information to and back. The form needs to display a grid of information and
pass back a yes/no field. Have been looking for some examples in the
tutorial area but have not found one. Dose any one now of a (good) example
of how to do something like this?
Thanks
Abraham Z.
Abraham
2005-11-03 17:12:16 UTC
Permalink
Thanks Allan,
Your posting has gotten me started in the right directions. Also thanks for
including the list from the developers guide. For sum reason, I can only see
the left side of the help screen. On the other side I get “The page cannot
be displayed”. I am still having problems getting the class to call a form.
This is what I have:
Form SalesTable\Data Source\SalesTable\PurchOrderFormNum\Methods\Modified

….
SalesDupPurch::dispDupPurch(SalesTable.CustAccount,
SalesTable.PurchOrderFormNum);
….


Table SalesDupPurch\Methods\dsipDupPurch
client void dispDupPurch(CustAccount custAccount,
CustPurchOrder custPurchOrder)
{
/* 11/01/05 A. Z. Created the Class
*/

FormRun formRun;
Args args = new Args();
;

args.record(this);
//args.parmObject(custAccount,custPurchOrder);
formRun = new MenuFunction(menuItemDisplayStr(SalesDupPurch),
MenuItemType::Display).create(args);
}

Debug tells me it executes the formRun = new … line but nothing happens.
SalesDupPurch is a form that has a menu item. I am trying to get a form to
display then work on passing variables back and forth.

Thanks for you help
Abraham Z.
Post by Allan Wallis
Look in the developers guide - search for Activating a menu item from your
X++ code
The text is reproduced below
Activating a menu item from your X++ code
To execute a menu item from your X++ code you use the MenuFunction system
class.
This is illustrated in the example below that is from the LedgerJournalTrans
table. The actual code extract is from the formSettlement method.
Note
Considering the new security system, you should create a menuitem, as
menuitems automatically inherit security settings.
egoby
2005-11-03 17:37:57 UTC
Permalink
Hey Abraham,

Regarding the issue with the page not being displayed in the DG - the file
might be blocked and you need to unblock it.

Try navigating to the developers guide help file (AxDvgUs.chm) which should
be located in:
Program Files\Navision\....\Axapta Client\Bin\AxDvgUs.chm

Right click on the file and display its properties --- if the file is
blocked, you'll see an option to unblock it at the bottom of the properties
form.

Hope this solves it.

Cheers.
Post by Abraham
Thanks Allan,
Your posting has gotten me started in the right directions. Also thanks for
including the list from the developers guide. For sum reason, I can only see
the left side of the help screen. On the other side I get “The page cannot
be displayed”. I am still having problems getting the class to call a form.
Form SalesTable\Data Source\SalesTable\PurchOrderFormNum\Methods\Modified
….
SalesDupPurch::dispDupPurch(SalesTable.CustAccount,
SalesTable.PurchOrderFormNum);
….
Table SalesDupPurch\Methods\dsipDupPurch
client void dispDupPurch(CustAccount custAccount,
CustPurchOrder custPurchOrder)
{
/* 11/01/05 A. Z. Created the Class
*/
FormRun formRun;
Args args = new Args();
;
args.record(this);
//args.parmObject(custAccount,custPurchOrder);
formRun = new MenuFunction(menuItemDisplayStr(SalesDupPurch),
MenuItemType::Display).create(args);
}
Debug tells me it executes the formRun = new … line but nothing happens.
SalesDupPurch is a form that has a menu item. I am trying to get a form to
display then work on passing variables back and forth.
Thanks for you help
Abraham Z.
Post by Allan Wallis
Look in the developers guide - search for Activating a menu item from your
X++ code
The text is reproduced below
Activating a menu item from your X++ code
To execute a menu item from your X++ code you use the MenuFunction system
class.
This is illustrated in the example below that is from the LedgerJournalTrans
table. The actual code extract is from the formSettlement method.
Note
Considering the new security system, you should create a menuitem, as
menuitems automatically inherit security settings.
Abraham
2005-11-03 21:27:17 UTC
Permalink
I have gotten the following code to work:
public void modified()
{
Object formRun;
// Form form; // already defined?
Args args;
;

...
// test if there are duplicate purchase orders with this customer
if(SalesDupPurch::findCustPurch(SalesTable.CustAccount,
SalesTable.PurchOrderFormNum))
{ // duplicate Purch
args = new args(formstr(SalesDupPurch));
args.caller(this);
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();
}

...
}

Still trying to figure out how to send data back and forth. All I need to
do is display the duplicate entries and ask if it is this a valid purhase
order number?

Abraham Z.
Post by Allan Wallis
Look in the developers guide - search for Activating a menu item from your
X++ code
Mike Frank
2005-11-04 10:47:26 UTC
Permalink
Post by Abraham
Still trying to figure out how to send data back and forth. All I need to
do is display the duplicate entries and ask if it is this a valid purhase
order number?
The best way would be to make accessor method in your class, obtain a
reference to the class in the form and do the data passing from the form
(getting data from the class maybe in the init and passing it back in
the close method).

Getting the classReference:

YourClass yourClassObject;

if (! element.args() || classidget(element.args().caller()) !=
classnum(YourClass))
{
throw error(Error::WrongUseOfFunction(funcname()));
}

yourClassObject = element.args().caller();

If you want to be completely correct and ready for future extensions of
your class you could use the condition
SysDictClass::isEqualOrSuperclass(classidget(element.args().caller()),
classnum(InventOnhand));

Mike

Continue reading on narkive:
Loading...