web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

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

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    302,372 Super User 2025 Season 2 on at

    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é

  • Brad Docimo Profile Picture
    485 on at

    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.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    302,372 Super User 2025 Season 2 on at

    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é

  • Community Member Profile Picture
    on at

    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 

  • Community Member Profile Picture
    on at

    [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.

  • supreme Profile Picture
    269 on at

    this is helpful

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
TAHER_El_Mehdi Profile Picture

TAHER_El_Mehdi 3

#2
Mea_ Profile Picture

Mea_ 2

#2
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans