在Dynamics ax中如何创建一个简单的对话框?
static void DialogSampleCode(Args _args)
{
Dialog dialog;
DialogField field;
;
dialog = new Dialog("My Dialog");
dialog.addText("Select your favorite customer:");
field = dialog.addField(typeid(CustAccount));
dialog.run();
if (dialog.closedOk())
{
info(field.value());
}
}
field = dialog.addField(extendedTypeStr(CustAccount)); //AX 2012
- ian_scho对于非常简单的对话框,使用Box Class:
Box::info("your message");
或者 Box::warning("your message");
或者 if (Box::okCancel("continue?", DialogButton::Cancel) == DialogButton::Ok)
{
// pressed OK
...
或者使用其他静态方法(infoOnce
, yesNo
, yesNoCancel
, yesAllNoAllCancel
, ...)之一。
DAX 2012没有"typeid"方法。但是您可以使用extendedTypeStr,然后传入已知的EDT或使用内置的字符串长度版本:
str getStringFromUser(str _prompt, str _title)
{
str userResponse = "";
Dialog dlg = new Dialog(_title);
DialogField dlgUserResponse = dlg.addField(extendedTypeStr(String15), _prompt);
// This prompts the dialog
if (dlg.run())
{
try
{
userResponse = dlgUserResponse.value();
}
catch(Exception::Error)
{
error("An error occurred. Please try again.");
}
}
return userResponse;
}