Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Dialog Validation

(0) ShareShare
ReportReport
Posted on by 485

I've found several posts and articles around the net talking about validating form fields in dialogs, but none of the examples I've found seem to work properly.

Can someone post a complete, concise example of x++ code that generates a dialog containing a single text field, performs simple validation (if text = "abc") on it, and either closes the window (returning the field value) if validation passes or generates an Infolog warning without closing the dialog if validation fails.

For those of us just beginning in x++, I think it would be a great starting point to have an actual working example to build on.

Thanks!

*This post is locked for comments

  • supreme Profile Picture
    supreme 269 on at
    RE: Dialog Validation

    this is helpful

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: Re: Re: Dialog Validation

    [quote user="Brad D"]I'm looking to either validate each field as it is changed or validate the entire dialog at once, but NOT allow it to close if validation fails.[/quote] 

    Take a look at 

    \Classes\InventABCUpdate\validate

    method for example. There is few dialog fields validation presented.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: Dialog Validation

    you can create a runbase class dialog where on standrad validate method you can validate on fields before the dialog is closed.

    Thanks,

    Yousef Shawareb 

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,160 Super User 2025 Season 1 on at
    Re: Re: Re: Dialog Validation

    Hi,

     

    In this case you need to create a form as dialog. On the form you can add some validation before closing it. There are some examples in standard AX2009:

    Form InventCostReportDialog which is called from report InventCostValue (method Dialog)

    Form  ProjEstimateListDialog which is called from report ProjEstimateList (method Dialog)

    but you can also use a form-based dialog on classes.

    regards,

    André

  • Brad Docimo Profile Picture
    Brad Docimo 485 on at
    Re: Re: Dialog Validation

    Thanks for the hint.  Unfortunately, this is what I have now.  I'm looking to either validate each field as it is changed or validate the entire dialog at once, but NOT allow it to close if validation fails.

    When I do it this way, the dialog closes whether or not validation passes or fails.

    Thanks again.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,160 Super User 2025 Season 1 on at
    Re: Dialog Validation

    Hi Brad,

    You can start with the following example. Just copy and past it into a new job.

     

    static void DialogJob1(Args _args)
    {
        Dialog      dialog;
        DialogField dialogField;
        Name        name;
        ;

        dialog      = new Dialog("please type ' abc'");
        dialogField = dialog.addField(typeid(Name),"Type value" );

        if (dialog.run())
        {
            name = dialogField.value();

            if (name == 'abc')
                info("well done, mate!");
            else
                throw error("This was the wrong value");

            // add code after validation
        }
        else
        {
            warning("Update cancelled by user");
        }
    }

     

     

    regards,

    André

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans