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)

Table Static Method events

(0) ShareShare
ReportReport
Posted on by 175

Hi,

The ProjEmplTrans table has a particular static method called initTransFromJournal that I would like to extend.

Here is a cut down version of it:

public static ProjEmplTrans initTransFromJournal(ProjJournalTrans _projJournalTrans)
{
    ProjEmplTrans  projEmplTrans;
   
...
projEmplTrans.TransId = _projJournalTrans.TransId; ...
return projEmplTrans; }

So this method has a single argument of ProjJournalTrans and it returns an instance of ProjEmplTrans.

As you may imagine, the ProjEmplTrans buffer is initialized from the ProjJournalTrans buffer.

I have added an additional field called InventAssetId to ProjJournalTrans and ProjEmplTrans.

When ProjEmplTrans.initTransFromJournal is executed I would like the InventAssetId to be copied from the journal transaction to the empl transaction like:

public static ProjEmplTrans initTransFromJournal(ProjJournalTrans _projJournalTrans)
{
    ProjEmplTrans  projEmplTrans;
   
...
projEmplTrans.TransId = _projJournalTrans.TransId;
    projEmplTrans.InventAssetId         = _projJournalTrans.InventAssetId;
    ...

return projEmplTrans;

}

Since overlayering is not an option, I created a POST event handler.  But for some reason, the XppPrePostArgs object does not contain the ProjEmplTrans return value - by this I mean that args.getReturnValue(); does not yield and instance of projEmplTrans. 

Given that this approach does not seem to work, how can I achieve this?

    [PostHandlerFor(tableStr(ProjEmplTrans), tableStaticMethodStr(ProjEmplTrans, initTransFromJournal))]
    public static void ProjEmplTrans_Post_initTransFromJournal(XppPrePostArgs args)
    {
                
        ProjEmplTrans projEmplTrans = args.getReturnValue();
        ProjJournalTrans projJournalTrans = args.getArg("_projJournalTrans");
        ;

        if(projJournalTrans.TransId)
        {
            info(strfmt("ProjJournalTrans exists and has TransId %1", projJournalTrans.TransId));
        }
        else
        {
            info("There is no ProjJournalTrans");
        }

        if(projEmplTrans.TransId)
        {
            info(strfmt("ProjEmplTransTable exists and has TransId %1", projEmplTrans.TransId));
        }
        else
        {
            info("There is no ProjEmplTransTable");
        }

      
        projEmplTrans.InventAssetId = projJournalTrans.InventAssetId;

    }


Thanks

Luke

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    I can't reproduce your problem - I'm getting correct data from getReturnValue().

    By the way, you should use Chain of Command instead if you can, it's easier and safer. Here is an example:

    [ExtensionOf(tableStr(ProjEmplTrans))]
    final class MyProjEmplTrans_Extension
    {
        public static ProjEmplTrans initTransFromJournal(ProjJournalTrans _projJournalTrans)
        {
            ProjEmplTrans emplTrans = next initTransFromJournal(_projJournalTrans);
            emplTrans.InventAssetId = _projJournalTrans.InventAssetId;
    
            return emplTrans;
        }
    }


  • Luke Shuttlewood Profile Picture
    175 on at

    Thanks Martin.   A much cleaner solution.

    So I now have: 

    [ExtensionOf(tableStr(ProjEmplTrans))]
    final class ProjEmplTrans_Extension
    {
        public static ProjEmplTrans initTransFromJournal(ProjJournalTrans _projJournalTrans)
        {
            ProjEmplTrans emplTrans = next initTransFromJournal(_projJournalTrans);
            emplTrans.InventAssetId = _projJournalTrans.InventAssetId;
    
            return emplTrans;
        }
    }

    On build I received this error:

    "The assembly which contains class 'ProjEmplTrans' is not compiled with chain of command feature, so method 'initTransFromJournal' cannot use chain of command in this extension class. "

    After a little research online it appears that the I need to (re)build the application model - or more specifically the "Application Suite" model for which ProjEmplTrans belongs to.  Is this entirely correct?  The model build has not completed yet, suspect it may be some time before it does so I'll report back later.

    I'm on platform update 10 - is this recent enough for CoC?

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

    Yes, you must recompile the package(s) that you're extending with CoC. And you must either do it in all environments, or you must distribute the recompiled code together with your changes (which is the only way you can use in production).

    The reason is that the compiler must generate extra CIL needed for CoC. Because the application has been compiled on an older platform, the resulting binaries don't contain these extra pieces.

    Yes, PU10 is sufficient.

  • Luke Shuttlewood Profile Picture
    175 on at

    All working  now.  Thank you very much for you help.

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans