Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

Purchase invoice: change posting profile when generating invoice from PO

(0) ShareShare
ReportReport
Posted on by
Hello,
I would like to know if it feasible to change the posting profile of an invoice when generating the invoice from a purchase order.
It is a custom requirement to check for certain criterias when clicking the Generate invoice button and if the criterias are true, then the invoice needs to have a different posting profile from that of the purchase order (and ultimately the changed posting profile account in the account entries).
What is the best approach to do this?
Is there any such method available to extend in PurchFormLetter_Invoice to implement this logic?
  • Jason0810M Profile Picture
    Jason0810M on at
    Purchase invoice: change posting profile when generating invoice from PO
    Hello Andre,
    The scenario is as follows:
    When posting an invoice of PO:
    If the sum of the vendor invoice line containing an AssetId is greater than the sum of non-asset vendor invoice line, then the invoice should have a different posting profile (as a different account should be charged).
    The problem with this is that the user can do partial invoicing. This means that if the aforementioned condition is false on a second posting, then the invoice should have the standard posting profile.
    I tried updating the VendInvoiceJour record only in the post of PurchInvoiceJournalCreate.createHeader() but the account is still the one associated to the standard posting profile in the GeneralJournalAccountEntries.
    I have tried a solution to add a new custom posting profile field on PurchTable.
    I have added the logic before the run of PurchFormLetter_Invoice to check if the condition is true based on the VendInvoiceInfoLine then update PurchTable.PostingProfile to the custom value and setting the PurchTable.XXXPostingProfile to the standard posting profile.
    If ever the condition is false for a second posting, then the PurchTable.PostingProfile will be updated to the PurchTable.XXXPostingProfile.
    It seems to be working in this way.
    However, I have a question regarding the implementation of the try catch.
    public void run()
        {
            int i = infologLine();
            try
            {
                tsbegin;
                this.customLogicToUpdatePurchTablePostingProfile(); 
            }
            catch
            {
                infolog.clear(i);
                if (appl.ttslevel()) == 0)
                {
                     ttsbegin;
                }
            }
            finally
            {
                next run();
                ttscommit;
            }
        }
    If ever there is a standard error in the run, then the update of PurchTable.PostingProfiles should be rollback. I have implemented the ttsbegin-ttscommit as shown.
    Is this the right approach to do it?
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,965 Super User 2025 Season 1 on at
    Purchase invoice: change posting profile when generating invoice from PO
    Hi Jason,
     
    Can you explain the exact business scenario functionally? What exact ledger accounts should be different? 
  • Jason0810M Profile Picture
    Jason0810M on at
    Purchase invoice: change posting profile when generating invoice from PO
    Any insight on this please?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans