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, ...
Suggested Answer

how to access variable inside main() method while creating COC ?

(0) ShareShare
ReportReport
Posted on by 1,010

Hi Team,

I am creating COC of main method of SalesFormLetter class. I want to access to the variable" numberofrecords" declared inside the main method in my COC but it is showing error "The qualifier "numberofrecords" is not valid in this context. Use a variable of this type instead."

can anyone suggest how to get the value in COC ?

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

    You can't access method variables with Chain of Command. Your COC code runs outside the wrapped method. And a method variable only exists within the method.

    But you can see that in this scenario numberOfRecords is fetched from the contract class: (outputContract.parmNumberOfOrdersPosted()). So you can fetch it from there.

  • D.K.S. Profile Picture
    1,010 on at

    Hi Nikolaos,

    can you please show me how to do that ? I tried but got the error that "output contract is not declared". Please find the below code.

    [ExtensionOf(classstr(SalesFormLetter))]

    final class LNTSalesFormLetter_Extension

    {

       public static void main(Args  args)

       {

           SalesTable      salesTable;

           Counter             locrecords;

           next main(args);

           if(args.menuItemName() == menuItemActionStr(SalesFormLetter_Proforma_Invoice_Action))

           {

               if(outputContract.parmNumberOfOrdersPosted() > 0 )

               {

                   salesTable = FormDataUtil::getFormDataSource(args.record()).cursor();//args.record();

               }

           }

       }

    }

  • Martin Dráb Profile Picture
    237,980 Most Valuable Professional on at

    Trying to wrap main() looks like a bad idea to me. Why don't you wrap an instance method, where you can access instance variables of the class?

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Next time you share your code, please click "Use rich formatting" and then Insert -> Insert code. This way your code will be easier to read.

    You can't get it by wrapping the main method. The contract is initialized inside main method.

    Could you please first explain what you are trying to achieve functionally?  Then we can suggest solutions.

  • Joris dG Profile Picture
    17,775 on at

    As others suggested, it would be good if you give an example or explain more what you're trying to do.

    Also, "main" is a static method, typically called from menu items. They typically just create an instance of the class and run it (with or without some sort of dialog first). It's likely you can create your own class with your own main() method, and do what you need to do. Potentially you can extend the original menu item to use your class instead.

    But again, it would be good to understand what you're trying to do.

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 420 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 241 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans