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 :
Finance | Project Operations, Human Resources, ...
Answered

Add my logic in extension before the standard method call in X++

(0) ShareShare
ReportReport
Posted on by 113

Hi Experts,

I want to write a logic  in MAP- InventInventoryJournalEntryMap in method -createJournalHeader with following condition.

1- If the JournalType = Movement and “Original journal No.” field has value.

2- If the existing Journal is “blocked” by system or any user.

If any of these two conditions are true than only the standard method will create a new  journal.

For this I have written a code but not working.

Can anyone tell how can I achieve this

[ExtensionOf(mapstr(InventInventoryJournalEntryMap))]
public final class CreateInventoryMomentJournal_CAP_Extension
{
    public static InventJournalTable createJournalHeader(JournalNameId _journalNameId, InventJournalType _expectedJournalType)
    {
        InventJournalTable inventJournalTable;


        inventJournalTable = next createJournalHeader(_journalNameId, _expectedJournalType);

        if (inventJournalTable.JournalType == InventJournalType::Movement && inventJournalTable.JournalIdOrignal ||
        inventJournalTable.SystemBlocked == NoYes::Yes)
        {
            InventJournalName inventJournalName = InventJournalName::find(_journalNameId);         

            if (inventJournalName.
            && inventJournalName.JournalType == _expectedJournalType)
            {
                inventJournalTable.initFromInventJournalName(inventJournalName);
                inventJournalTable.VoucherDraw = JournalVoucherDraw::Post;
                inventJournalTable.insert();
            }

            else
            {
                throw error(strFmt("@SYS22977", _expectedJournalType));
            }
            
          
        return inventJournalTable;
    }

}

I have the same question (0)
  • Martin Dráb Profile Picture
    238,848 Most Valuable Professional on at

    Please never describe a problem by mere "not working", because it can mean absolutely anything. Instead, describe the actual behavior to us. For example, maybe you get an error and should tell us where it's thrown and what the error message says.

    Your code looks syntactically wrong to me, because you're trying to call next createJournalHeader() twice, and the logic doesn't meet your requirements.

    You need to think about what exactly you want to do if you condition is met. Don't you want to throw an exception, for instance?

    By the way, it's not necessary to add all the tags like "dynamics 365 finance & operation". This whole forum is about F&O, therefore these tags add no information.

  • HARISH MEHRA Profile Picture
    113 on at

    Hi Martin,

    Done the changes as you said.

    About problem - When I am running the process the standard method creates the journal before checking my condition .

    Thanks

  • Martin Dráb Profile Picture
    238,848 Most Valuable Professional on at

    Yes, of course. You call the standard logic at line 9 and check your condition later, at line 11.

  • Alex VN Profile Picture
    1,994 on at

    Hi,

    In addition to Martin, to avoid confusion, the standard call will be called when you have next call on line 9. Hence you can put your own logic before line 9 to apply before standard call.

  • HARISH MEHRA Profile Picture
    113 on at

    Hi Anh,

    I can write my logic before next that is fine. But the main thing here is how can I stop standard from making a new journal if conditions fail.

    Thanks

  • Martin Dráb Profile Picture
    238,848 Most Valuable Professional on at

    What code you should write depends on what behaviour you want to get. That's what you need to start thinking about.

    One suggestion given to you is throwing an exception. Unfortunately, you've never told us whether it meets your requirements or not.

  • Verified answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Harish, I think the issue for you is that even if you write your logic before next statement, it will work only  when your conditions are not met and error is thrown. However, when your conditions are passed your code will create a record in inventJournalTable then it will then call to super which will either try to create new record or throw error, so it will be issue.

    One way is to create duplicate method of createJournalHeader and call that method instead in the following two methods. You have to CoC on below methods to bypass standard logic and then call everything in your methods.

    • /Maps/InventInventoryJournalEntryStagingMap/Methods/postGetStagingData
    • /Maps/InventInventoryJournalEntryMap/Methods/setJournalNumber

    Note: If you proceed with this approach, any updates on those methods by Microsoft in future will impact your solution as you will be duplicating standard method.

  • HARISH MEHRA Profile Picture
    113 on at

    Thankyou for the suggestions.

    I have written the logic in - Maps/InventInventoryJournalEntryMap/Methods/setJournalNumber.

    And now logic is working.

    Thanks & Regards,

    Harish

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 470

#3
Adis Profile Picture

Adis 270 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans