3

I have created a wizard in AX 2012 using wizard wizard... Now i need to put 1 functionality i.e., to Enable or Disable FINISH button based on user input.

I have already tried these 3 ways but without success..

this.finishenabled() -- on SetupNavigation method of wizard class

finishenabled[formrun.tabidx()] = false -- on SetupNavigation method of wizard class

syswizard.finishenable(false, curtabidx(),false) - on Tabpage of wizard form

please do reply if anyone have a solution for this....

Jan B. Kjeldsen
  • 17,817
  • 5
  • 32
  • 50
Mohd Saddaf khan
  • 289
  • 2
  • 14
  • 26

3 Answers3

5

The Wizard class has a validate method in which you will do the following:

boolean validate()
{
    if(SomeTestCondition)
    {
        return true;
    }
    return false;
}

According to Microsoft, this method does the following:

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. Wizard Class on MSDN

Additionally, you can use the textchanged() method on the field you want to validate (or if not text, you can use the changed method of the object).

if (this.text())
{
    if   (!sysWizard.isNextEnabled())
    {
        sysWizard.nextEnabled(true,   sysWizard.curTab(), false);
    }
}
else
{
    if   (sysWizard.isNextEnabled())
        sysWizard.nextEnabled(false,   sysWizard.curTab(), false);
}

Also from MSDN Enable Buttons

Michael Brown
  • 2,221
  • 2
  • 17
  • 34
  • Thanks for reply.Actually I need to disable Finish button particularly...I am well aware of Validate and disable Next. Bt how to disable FINISH button in particular???? – Mohd Saddaf khan May 23 '13 at 12:44
  • The bottom part, explains this. You can disable the finsh button based on the user input. If Finish button is the next button then SysWizard.nextEnabled would reference the finsihed button – Michael Brown May 23 '13 at 15:12
0

In SysWizard class the check to enable / disable the finishButton is inside a check for this.hasFinishButton() (see SysWizard.enableButtons).

I overcame this issue by overwriting the hasFinishButton() method on your wizard class and set the ret = true. This does mean however that your finish buttons will show in all steps, but you can hide this with other code if necessary.

Celeste
  • 106
  • 1
  • 13
0

The simplest way to enable/disable the Finish button on a Wizard form called from a SysWizard class is to retrieve the FormControl object from the FormRun object using the FormControlId and then set the Enabled property based on the your test condition, such as whether another FormControl contains a value. There are many ways to implement this. I'll provide two examples.

In the first example, all of the modifications are done on the Wizard Form. A FormControl is used that can be called like any FormControl that has the AutoDeclaration property set to Yes. In the second example, I'll override the finishEnabled() method on my Wizard class, so it behaves in the manner that was expected.

In each example, the formControl is found using the FormControlId which takes the control's label text ("Finish") as the argument. I found the correct Label ID by doing a "Lookup Label/Text" on "Finish" in the code editor and then selected the SYS label with "Label for Finish button in wizard" in the label's Description.

Example 1: FormControl object on Wizard Form:

In the Form classDeclaration add the following:

class FormRun extends ObjectRun
{
    //FormControl objects used to get SysWizard Finish Button
    FormControlId   finishButtonId;
    FormControl     finishButton;
}

Initialize the new FormControl in the top level Form init() method:

void init()
{
    super();
    if (element.Args().caller())
    {
        sysWizard = element.Args().caller();
    }

    finishButtonId  = sysWizard.formRun().controlId("@SYS302811");
    finishButton    = sysWizard.formRun().control(finishButtonId);

    finishButton.enabled(false);    
}

Now you can use the control like you would any other form control. In this case, I'm using the state of checkbox control named IsFinished in my WizardForm as the test condition and updating the FormControl state from the IsFinished.clicked() method:

public void clicked()
{
    super();

    //set FormControl state based on the current value of the checkbox
    finishButton.enabled(this.checked());
}

*Example 2:*Override the finishEnabled() method in your Wizard class:

Note that you'll need to set the default values for the method parameters otherwise AX will throw a compile error because it doesn't match the signature from the base class. For some reason, AX doesn't properly create the method signature. Get rid of the default call to super and replace it with the code below:

public boolean finishEnabled(boolean _enabled  = false, 
                             int     _idx      = this.curTab(),
                             boolean _setfocus = false)
{
    return this.formRun().control(this.formRun().controlId("@SYS302811")).enabled(_enabled);
}

Initialize the control value in the Form init() method:

void init()
{
    super();
    if (element.Args().caller())
    {
        sysWizard = element.Args().caller();
    }

    sysWizard.finishEnabled();    
}

Call the class method when your controls are updated:

public void clicked()
{
    super();

    //set FormControl state based on the current value of the checkbox
    sysWizard.finishEnabled(this.checked());
}