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 150

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

  • PaulaRystemi6 Profile Picture
    150 on at
    RE: Call a menuitem of type display with different datasources based on the current record onclicked() button event.

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

  • Community Member Profile Picture
    on at
    RE: Call a menuitem of type display with different datasources based on the current record onclicked() button event.

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

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Call a menuitem of type display with different datasources based on the current record onclicked() button event.

    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

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Call a menuitem of type display with different datasources based on the current record onclicked() button event.

    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.

  • PaulaRystemi6 Profile Picture
    150 on at
    RE: Call a menuitem of type display with different datasources based on the current record onclicked() button event.

    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,156 Moderator on at
    RE: Call a menuitem of type display with different datasources based on the current record onclicked() button event.

    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);
    
    }

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,276 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,975 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans