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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

using args class

(0) ShareShare
ReportReport
Posted on by

I have a menu item in a form when it is clicked a class is called. The form has two data sources. How can I retrieve the active records data of the two data source  inside the class to do required calculation ?

*This post is locked for comments

I have the same question (0)
  • Dick Wenning Profile Picture
    8,705 Moderator on at

    on the property of the menuitem in the form, there is a method called, datasource,

    this is most of the time the same on the grid, also multiple selection is possible.

    next the menu item can point to  a class, in that case it called the static main method.

    this main method has an _args Method.

    next example does something like that

    // Called from EP for changing the status of an activity

    static void main(Args args)

    {

       Common                  record      = args.record();

       smmActivities           smmActivities;

       FormDataSource          dataSource;

       ;

       if (!args)

       {

           throw error("@SYS25407");

       }

       if (record)

       {

           smmActivities = record;

  • Suggested answer
    Martin Dráb Profile Picture
    239,680 Most Valuable Professional on at

    You can pass only a single record in Args.record(), nevertheless you can use other properties to get the other data source. You can use caller() to get the caller form and access all data sources (FormRun.dataSource()) or you can send the reference in parmObject() (it can be even used for passing multiple values packed in a class).

  • maram fraij Profile Picture
    on at

    if the caller form has many datasources, how can I determine to which datasource the record returned by Args.record() belongs?

  • Martin Dráb Profile Picture
    239,680 Most Valuable Professional on at

    You can find table ID by Args.dataset() or Args.record().TableId. If you have more data sources for the same table, you would have to check the name of the data source, relationships or something else that you can interpret in your case.

  • Suggested answer
    Kumar Gaurav @ MS Profile Picture
    on at

    Besides above mentioned solutions , you can also create method on the form to pass reference of data source and through caller object you can catch those references in class, however you need to be careful in doing this because if not properly validated at class level this can lead to run time errors for other callers.

  • Suggested answer
    Community Member Profile Picture
    on at

    in this case I would suggest write all the calculation logic in a method in the form itself and access the form method on form in class using args.caller()

    Please verify and update with your finding

    and let me know if you need further support related to this customization

  • Martin Dráb Profile Picture
    239,680 Most Valuable Professional on at

    I must oppose the suggestion to write business logic in forms - it causes many troubles. Collect parameters  and send them (you can use a class to group them) to a class which will do the logic not related to user interface.

  • Suggested answer
    Dick Wenning Profile Picture
    8,705 Moderator on at

    multiple records is possible.

    msdn.microsoft.com/.../aa557882.aspx

    this example should be placed in the main of the class.

    the datasource is also available in args class

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dserp Profile Picture

dserp 4

#2
dekion Profile Picture

dekion 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans