Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Prevent changed of grid selection

(0) ShareShare
ReportReport
Posted on by 38

Hi,

I want to prevent user from switching to other record in grid, similar to 'ProdRoute' Form. If you create a new record via new button on that forms action pane, a new column is created in the grid. however if you dont fill all mandatory fields and try to select another record, a warning is shown and the selection doesn't change until you give all information. can you give me an idea on how to do that? i tried with overwritign leaverecord, validatewrite and active method with no success.

best regards

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Prevent changed of grid selection

    Can you please share some screenshots to illustrate that?

    1) A screenshot of validateWrite method of the CustGroup data source

    2) Screenshot of CustGroup form where you have started creating a new record

    3) Screenshot of CustGroup form where you succesfully selected another record after trying to create a new one

    Anyway, if that's the case, then the problem is in your system, and not in your code. In which case it's not useful to focus on the code anymore. But I suspect that you are somehow missing some detail, that's the most likely explanation. But not the only one :)

  • erpdell Profile Picture
    erpdell 38 on at
    RE: Prevent changed of grid selection

    I can select another record...

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Prevent changed of grid selection

    There must be something wrong but we don't yet see it in the details that you shared.

    Just to illustrate a simple example that you can examine, let's use a simple form, CustGroup.

    Go to the CustGroup data source, override validateWrite method so that it always returns false.

    Now, try to create a new record in the form, and see if you can select another record in the grid. I can't.

  • erpdell Profile Picture
    erpdell 38 on at
    RE: Prevent changed of grid selection

    Yes.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Prevent changed of grid selection

    The grid itself has a property called DataSource. Is it ProdRoute?

  • erpdell Profile Picture
    erpdell 38 on at
    RE: Prevent changed of grid selection

    Right. Sorry I am new to AX, how do I know if it's the Primary data source?

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Prevent changed of grid selection

    Ok so if you click ctrl+s it's called ,but not when you click another record in the grid?

    Is ProdRoute the primary data source of your grid?

  • erpdell Profile Picture
    erpdell 38 on at
    RE: Prevent changed of grid selection

    Good idea, however nothing is printed.

    Edit: It is getting called, when I try to save by pressing ctrl+s

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Prevent changed of grid selection

    If your breakpoint is not hit, it could also just mean that the debugger didn't kick in. But the code might still be executed. I think that the debugger doesn't really kick in when debugging methods in form sub-elements (data sources, controls...).

    Just to be sure, could you add an infolog in your validateWrite, to print the return value to infolog?

    public boolean validateWrite()
    {
        boolean ret = super() && this.isValid();
        info(strFmt("%1", ret));
        return ret;
    }

  • erpdell Profile Picture
    erpdell 38 on at
    RE: Prevent changed of grid selection

    I've set a breakpoint at method head? Thanks for your advice, i've had it like that beforehand

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…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,329 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans