Thursday, 16 January 2014

Wizard in AX

Wizard
A wizard is a special form of user assistance that takes the user through a task by using a series of dialog boxes. Wizards are especially useful for complex or infrequent tasks that the user may have difficulty learning or doing, or for tedious, frequently performed tasks.
Standard AX Wizards available, ( Report Wizard, Project Wizard, Number Sequence Wizard)
·        The Report Wizard simplifies report generation process by leading the user through the steps necessary for creating a report. The wizard provides identical functionality to the commands in the Report node's shortcut menu.
·        The Class Wizard guides you through all the required selections necessary to create a class, and allows you to inherit from an existing Microsoft Dynamics AX class
Wizard is used to help a user to perform a specific task, and is presented as a form with a series of steps. While running Wizard all user inputs are stored in temporary memory until the user presses Finish in Last page.
Wizard Types :
·        Standard – Helps user perform general tasks.  Ex : Report Wizard
·        Default Data Wizard – Help users create essential default data – Address information, Number sequence framework.  All default Data Wizards are automatically included in the systems, Default data wizard.


Demo :  To create new Wizard for creating main accounts.

1. Open Tools | Wizards | Wizard.
2. Click on Next on the first page:
3. Select Standard Wizard and click on Next
4. Specify MainAccount in the name field and click on Next:



5. Accept the default number of steps ( ie., 3) and click on Next:
6. Click on Finish to complete the wizard
7. The wizard creates an AOT development project, with three new objects in it: a form, a class, and a menu item.
8. Create a new macro library named MainAccountWizard with the following code:
#define.tabStep2(2)
9. Modify the MainAccountWizard class by adding the following code to its class declaration:
MainAccount mainAccount;
#MainAccountWizard
10. Add the following line to the existing setupNavigation() method in the same class:
nextEnabled[#tabStep2] = false;
11. Override the finish() method of the class with the following code:
protected void finish()
{
mainAccount.initValue();
mainAccount.LedgerChartOfAccounts =
LedgerChartOfAccounts::current();
mainAccount.MainAccountId = formRun.accountNum();
mainAccount.Name = formRun.accountName();
mainAccount.Type = formRun.accountType();
super();
}
12. Replace the validate() method of the same class with the following code:
boolean validate()
{
return mainAccount.validateWrite();
}
13. Replace the run() method of the same class with the following code:
void run()
{
mainAccount.insert();
info(strFmt(
"Ledger account '%1' was successfully created",
mainAccount.MainAccountId));
}
14. In the MainAccountWizard form, add the following code to the class declaration:
#MainAccountWizard
15. Change the form's design property:  [Caption – Main Account Wizard]
16. Modify the properties of Step1 [ Caption – Welcome]
17. Add new Static Text Control – [ Name – Welcome Txt , Text – This wizard helps you to create a new main account]
18. Step 2  [ HelpText – Specify Account number, name and Type, Caption – Account setup]
19 Add new String Edit Control
[ Name – AccountNum, AutoDeclaration – yes, Label – Main account , ExtendedDataType – AccountNum]
20.  Add new String Edit Control
[ Name – AccountName, AutoDeclaration – yes, ExtendedDataType – AccountName]
21.  Add new String Edit Control
[ Name – AccountType, AutoDeclaration – yes,  EnumType  – DimensionLedgerAccountType]
22. Modify Step 3 [ Caption – Finish]
23. Add  new Static Text Control [ Name – FinishTxt , Text – This Wizard is now ready to create new main account.]
24. Create the following four methods at the top level of the form:
public MainAccountNum accountNum()
{
return AccountNum.text();
}

public AccountName accountName()
{
return AccountName.text();
}

public DimensionLedgerAccountType accountType()
{
return AccountType.selection();
}

public void setNext()
{
sysWizard.nextEnabled( this.accountNum() && this.accountName(), #tabStep2, false);
}
25. Now override the textChange() method on the AccountNum and AccountName controls with the following code:
public void textChange()
{
super();
element.setNext();
}


Methods :

1.      Enabling Wizard Buttons Depending on User Input :

Set the initial state of the button by using the setupnavigation method.
Test for user input, and then use the nextEnabled method to enable the button If the user input has been validated.

The setupNavigation method allows you to set the initial states of the Back and Next buttons on your wizard. This method is available if you have based your wizard on the SysWizard class

void setupNavigation()
{
// First, complete the name.
    nextEnabled[formRun.namesTabIdx()]          =   false;
// Default data tabbed page.
    skipTab[formRun.defaultDataSetupTabIdx()]   = true; 
}

 The second parameter specifies the tab page where the Next button should be enabled. The default is the current tab page. The third parameter indicates whether focus should be moved to the Next button; the default is true.
if (this.text())
{
    if   (!sysWizard.isNextEnabled())
    {
        sysWizard.nextEnabled(true,   sysWizard.curTab(), false);
    }
}
else
{
    if   (sysWizard.isNextEnabled())
        sysWizard.nextEnabled(false,   sysWizard.curTab(), false);
}


Useful Methods of SysWizard  Class :

Method
Description
validate
Used to validate user input, and called before the wizard is closed.
It returns false if user input is invalid. This will prevent the run method from being called when the user clicks the Finish button.
formRun
Returns a formRun, which is an instance of the form of the same name as the class.
This method is always overridden but should not be changed.
static void main(args args)
Creates a new instance of the wizard and calls wizard.run on the SysWizard class.
This method is always overridden, but should not be changed.
run
Called when the user clicks the Finish button if validate returned true.
setupNavigation
Use this method to set up whether the Next and Back buttons should be enabled from the start.
All Back and Next buttons are enabled by default, except for the Back button in the first step and the Next button in the last step.
skipTab
Allows you to skip a tab page when certain conditions are met.


Useful Methods of  SysDefaultDataWizard Class :

Method
Description
enabled
Determines whether the wizard should be displayed in the list of basic setup wizards.
mustRun
Determines if base data exists or if it should be created by the wizard.
description
Returns a short description of what the wizard does.
The description is used in the wizard's caption if the Caption property has not been set.






No comments:

Post a Comment