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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Call a menuitem of type display with different datasources based on the current record onclicked() button event.

(0) ShareShare
ReportReport
Posted on by 152

Hello all,

I  have a button, wich when clicked... i need to show a display menu item with different datasources based of the name of the dataset that the selected record is.

For example :

if the dataset of the selected record is custtable --> show the menuitem of type display with SalesTable  as datasource , otherwise show the menuitem with SalesLine as datasource.

All the datasources that i will add on code are part of form datasources.

I want to know:

1. How to check wich is the name of the current record dataset.

2. How to call the menuitem with a specific datasource .

I am onclicked() of button event.

Thank you in advance

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Normally each button is linked to one data source. If you do it like this, you would need one button for SalesLine data source and one for SalesTable, and no development would be needed. I recommend to use this approach, because that's how the system generally works.

    If you want to change the data source based on latest selected record, you need to maintain the information about the selected record somewhere. You should create a form level variable of type Common, and then assign SalesLine / SalesTable to the variable in active method of corresponding data sources. But it might not be so intuitive for the user to understand which one is really the last selected data source.

    This is just an illustration, which demonstrates the idea - no guarantees and I don't recommend to use it:

    // Put this in the class declaration of your form:
    
    Common mySelectedRecord;
    
    // Put this in active method of SalesTable data source
    public void active()
    {
        super();
        mySelectedRecord = SalesTable;
        
    }
    
    // Put this in active method of SalesLine data source
    public void active()
    {
        super();
        mySelectedRecord = SalesLine;
        
    }
    
    // Put this in clicked method of your MenuItemButton
    public void clicked()
    {
        MenuFunction menuFunction = this.menuFunction();
        Args args = new Args();
        args.caller(element);
        args.record(mySelectedRecord);
        
        menuFunction.run(args);
    
    }

  • PaulaRystemi6 Profile Picture
    152 on at

    is there any way do do it onclicked() method?

    I have suggested the way of adding two buttons but the client didnt like it.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    OnClicked is too late, the menu function has already been launched at that point.

    But if it's not a menu item button, then onClicked will work, too. The code is of course a bit different, you need to define MenuFunction instead of getting it from the button properties. And you are responsible of showing/hiding the button if it should not be accessible by all users who can open the form. With MenuItemButton the security framework takes care of it for you.

    Or, develop a class that you run with your MenuItemButton, and put the logic there.

    But mySelectedRecord needs to be handled on the form.

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    Write something like that in your clicked method:

    Args args = new Args();

    args.record(element.args().record()); // your datasource record // you can write if statements and select the proper datasource for the menuitem

    args.caller(this);

    new MenuFunction(menuItemDisplayStr(yourdisplaymethod), MenuItemType::Display).run(args); // use display method

  • Community Member Profile Picture
    on at

    P.S Keep in mind that your button should be a simple button, not a menuitembutton.

  • PaulaRystemi6 Profile Picture
    152 on at

    thank you, in fact i solve it in this way as a simple button and it was ok :)

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans