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 :
Microsoft Dynamics AX (Archived)

Could not able to access the global variable in the event handler class using reflections in ax 7

(0) ShareShare
ReportReport
Posted on by 302

Hello!,

I couldn't able to access the global variable in the post event handler class using reflections concept in D365.

Please see the following image for further reference,

Rea.PNG 

Hence I am getting an exception,

Rea1.PNG

Rea2.PNG

However the same process is working fine in platform update 7.

I am currently working on platform Update 10 and its not working for me in platform Update 10.

Please suggest any solutions.

Thanks,

*This post is locked for comments

I have the same question (0)
  • Wekey Profile Picture
    302 on at

    Hello Everyone!,

    Any Updates on this?

    Thanks.

  • Suggested answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    journalNum isn't a global variable, it's a protected instance variable of AssetJournal class and your code is trying to bypass safety boundaries of encapsulation by hacking into internal representations that are subject to change. Stop this hacking ASAP if you don't want to get to more troubles!

    The right approach is using Method wrapping and Chain of Command.

  • Wekey Profile Picture
    302 on at

    Hello Martin,

    Thanks for your reply. Ya I was looking for this Chain of command concept, but I couldnt able to get it right. As I am trying to extend asset journal class and using the method populateLedgerJournalTrans I dont know to which buffer i have to aplly the next statement inorder to get the journalNum .

    Please help me with the coding.

    Thanks

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

    The "next" keyword is used to call the original method or another wrapper method in the chain, not to get any values. You refer to class variables by name.

  • Wekey Profile Picture
    302 on at

    I tried to call my method like this,

    var a = next populateLedgerJournalTrans(

                                     _amount,

                                     _assetBook,

                                     _transDate,

                                     _assetBudgetModelId,

                                     _period,

                                     _consumptionQty,

                                     _revaluationTrans,

                                     _revaluationAmount,

                                     _custTransId,

                                     _firstTransDate,

                                     _isPriorYear,

                                     _assetDocumentType,

                                     _assetDocumentEntryRecId,

                                     _prevLedgerJournalTrans,

                                     _ledgerJournalTransTxt,

                                     _defaultDimension_RU

           );

    But I am getting this following error,

    The expression 'Next populateLedgerJournalTrans ( System.Collections.Generic.List`1[System.Tuple`2[System.Boolean,Microsoft.Dynamics.AX.Metadata.XppCompiler.Expression]] )' returns void and cannot be used in an assignment.

    Correct me where I am wrong and I am a beigineer, sorry for bothering too much.

    Thanks

  • Wekey Profile Picture
    302 on at

    I tried to call my method like this,

    var a = next populateLedgerJournalTrans(
                                      _amount,
                                      _assetBook,
                                      _transDate,
                                      _assetBudgetModelId,
                                      _period,
                                      _consumptionQty,
                                      _revaluationTrans,
                                      _revaluationAmount,
                                      _custTransId,
                                      _firstTransDate,
                                      _isPriorYear,
                                      _assetDocumentType,
                                      _assetDocumentEntryRecId,
                                      _prevLedgerJournalTrans,
                                      _ledgerJournalTransTxt,
                                      _defaultDimension_RU
            );

    But I am getting this following error,

    The expression 'Next populateLedgerJournalTrans ( System.Collections.Generic.List`1[System.Tuple`2[System.Boolean,Microsoft.Dynamics.AX.Metadata.XppCompiler.Expression]] )' returns void and cannot be used in an assignment.

    Correct me where I am wrong and I am a beigineer, sorry for bothering too much.

    Thanks

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

    The message is very clear. It says that populateLedgerJournalTrans() doesn't return any value, therefore trying to assign its return value to a variable (a = populateLedgerJournalTrans()) makes no sense.

  • Wekey Profile Picture
    302 on at

    But when I try the following code,

    [Extensionof(classStr(AssetJournal))]
    final class AssetJournalTES_Extension
    {
        public void populateLedgerJournalTrans(
                AmountCur                      _amount,
                AssetBook                      _assetBook,
                TransDate                      _transDate,
                AssetBudgetModelId             _assetBudgetModelId,
                AssetDepreciationTime          _period,
                AssetConsumptionQty            _consumptionQty,
                AssetRevaluationTrans          _revaluationTrans,
                AssetRevaluationAmount         _revaluationAmount,
                RecId                          _custTransId,
                TransDate                      _firstTransDate,
                boolean                        _isPriorYear
                // <GJP>
                ,AssetDocumentType_JP          _assetDocumentType
                ,AssetDocumentRecId_JP         _assetDocumentEntryRecId
                ,LedgerJournalTrans            _prevLedgerJournalTrans
                // </GJP>
                ,LedgerJournalTransTxt        _ledgerJournalTransTxt
                ,DimensionDefault             _defaultDimension_RU
            )
        {
            LedgerJournalTable ledgerJournalTable;
            next populateLedgerJournalTrans(
                                      _amount,
                                      _assetBook,
                                      _transDate,
                                      _assetBudgetModelId,
                                      _period,
                                      _consumptionQty,
                                      _revaluationTrans,
                                      _revaluationAmount,
                                      _custTransId,
                                      _firstTransDate,
                                      _isPriorYear,
                                      _assetDocumentType,
                                      _assetDocumentEntryRecId,
                                      _prevLedgerJournalTrans,
                                      _ledgerJournalTransTxt,
                                      _defaultDimension_RU
            );
    
            ledgerJournalTrans.JournalNum = journalNum;
            ledgerJournalTable = ledgerJournalTrans.ledgerJournalTable();
    
            if (ledgerJournalTrans_Asset.TransType)
            {
                LedgerJournalTrans.editReasonCode(true, LedgerJournalName::find(LedgerJournalTable.JournalName).Reason); 
            }
    
        }
    
    }


    I get this error, 

    The qualifier 'ledgerJournalTrans' is not valid in this context. Use a variable of this type instead.

  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    There is a known problem with the compiler, which is going to be fixed in Platform Update 11.

    For now, create a new local variable and assign ledgerJournalTrans there, then use the new local variable. For example:

    LedgerJournalTrans trans = ledgerJournalTrans;
    trans.JournalNum = journalNum;
  • Suggested answer
    Cronqvist Profile Picture
    60 on at

    The problem still exists in Platform Update 15.

    I too think its a compiler issues, and the fact that the variable is not marked as public. The parmLederJournalTrans method, on the other hand, is public and you can do like this:

    this.parmLedgerJournalTrans().JournalNum = journalNum;

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans