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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to use Menu Name in If statement to perform certain Logic.

(0) ShareShare
ReportReport
Posted on by 353

Hello All - 

    

We have a trade agreement Menu Item in Ax under Sales and Marketing> Common > customers > all customers
and We have the same Menu Item in Sales and Marketing> Journals > Price/discount agreement journal. Both of these paths open up the same form. Now I have made some customizations on the form which opens up from these menu items but I only want the customizations to work from Sales and Marketing> Common > customers > all customers > Trade agreement and not from this path Sales and Marketing> Journals > Price/discount agreement journal. How Can I do this ? How Can I put a condition which will decide the path which is used to access this MenuItem ?? both the Menuitems use the same caller PriceDiscAdmSearch. 

Thank You-

Muhammad Ali

*This post is locked for comments

I have the same question (0)
  • Muhammad_Ali Profile Picture
    353 on at

    Im also posting my code the changes I have made are in the comment tags // WF - Muhammad Ali 

    I only want these changes to work when the user uses the path 

    Sales and Marketing> Common > customers > all customers > TradeAgreements

    public void init() // This is the init() method of the forms datasource which is a tempTable.

    {

       PriceDiscAdmTrans PriceDiscAdmTrans;

       super();

       if (priceDiscAdmSearch.parmTmpPriceDiscAdmSearchCust())

       {

           tmpPriceDiscAdmSearchCust.data(priceDiscAdmSearch.parmTmpPriceDiscAdmSearchCust());

           tmpPriceDiscAdmSearchCust.insert();

           tmpPriceDiscAdmSearchCust_PriceGroupType.enabled(tmpPriceDiscAdmSearchCust.isForGroup());

           tmpPriceDiscAdmSearchCust_AccountRelation.enabled(!tmpPriceDiscAdmSearchCust.isForAll());

       }

       else

       {

           tmpPriceDiscAdmSearchCust.Module = ModuleInventCustVend::Cust;

           //WF- Muhammad Ali

                 tmpPriceDiscAdmSearchCust.IncludeAdditionalRelations = NoYes::No;

                 PriceDiscAdmTrans.AccountCode = TableGroupAll::Table;

                 tmpPriceDiscAdmSearchCust.AccountRelation =  priceDiscAdmSearch.ParamCustAccount();

           // WF - Muhammad ALi

           tmpPriceDiscAdmSearchCust.insert();

           tmpPriceDiscAdmSearchCust_PriceGroupType.enabled(false);

    }

  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    Hi Muhammad_Ali,

    Using element.args().caller() you can get caller form, caller form has args as well, so you can check caller of the caller. and see if it was cust table or not.

  • Suggested answer
    dynamics developer Profile Picture
    2 on at

    Hi Ali,

    You can duplicate the menu item to make a copy and use the Parameters property on the menuitem to identify your case.

    for example

    if (element.args() && element.args().parm() && element.args().parm() == "parameterValue")
    {
         //statements
    }

    Or you can even create an enum with the two form names and use the enumTypeParameter and enumParameter properties to identify you form.


  • dynamics developer Profile Picture
    2 on at

    Actually you already have two different menu items 'PriceDiscAdmTable_Sales' for Sales and Marketing> Journals > Price/discount agreement journal and 'PriceDiscAdmTable_SalesCreate' for Sales and Marketing> Common > customers > all customers . So just add some value in the parameter property for the second one and use it.

    or just use the suggestion above to identify from caller since that's a more simpler n feasible approach

  • Muhammad_Ali Profile Picture
    353 on at

    Thank You for the Reply Haris. I have one more question I know we can use element.args().caller() to find the caller form. but what if I want to find the caller of the caller ? Im trying to use element.args().caller().args().caller(); but Im getting the error " The variable is not of Type class ? Can you suggest me something ? Thanks

  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    Hey Muhammad_Ali,

    You cannot use element.args().caller().args().caller() but you can break it into several lines:

    Object  caller;    
    
    Args    args;
    
    caller = element.args().caller();
    
    if (caller)
    {
        args = caller.args();
    
        caller = args.caller();
    }


  • Muhammad_Ali Profile Picture
    353 on at

    Thanks for the reply ievgen I tried this approach but at line args=caller.args(); Im getting the error " DialogRunbase object does not have method args" any idea why ? and how I can fix this ?

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Yep it's bit more complicated with Dialog. If you will look at main() method of PriceDiscAdmSearch you will see some logic to analyze caller. So you can probably create a variable to store caller or a custom flag to indicate caller of a dialog, then you can create public method on  PriceDiscAdmSearch  to expose new variable and use it inside of the form.

  • Verified answer
    dynamics developer Profile Picture
    2 on at

    Or if you want to avoid complication better use the enum parameter method :)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans