Skip to main content
Question

Sales Order (CM) - Defaulting Post Period and Invoice Date to Current Period and Date


Forum|alt.badge.img

Hi there,

 

 

I have a requirement to default the Invoice Date and Post Period in SO Invoice as the current date and period and was able to achieve it as shown below:


        protected void ARInvoice_RowInserted(PXCache sender, PXRowInsertedEventArgs e)
        {
            ARInvoice doc = e.Row as ARInvoice;
            if (doc == null) return;

            // Ensure it's a Credit Memo created from a Sales Order
            if (doc.DocType == ARDocType.CreditMemo && doc.OrigModule == "SO")
            {
                doc.DocDate = PXTimeZoneInfo.Now.Date;

                FinPeriod currentFinPeriodID = PXSelect<FinPeriod,
                    Where<FinPeriod.startDate, LessEqual<Required<FinPeriod.startDate>>,
                        And<FinPeriod.endDate, Greater<Required<FinPeriod.endDate>>,
                        And<FinPeriod.active, Equal<True>>>>>
                    .Select(Base, doc.DocDate, doc.DocDate);

                if (currentFinPeriodID != null)
                {
                    string month = currentFinPeriodID.FinPeriodID.Substring(4, 2);
                    string year = currentFinPeriodID.FinPeriodID.Substring(0, 4);
                    string finPeriodID = string.Concat(month, year);
                    sender.SetValueExt<ARInvoice.finPeriodID>(doc, finPeriodID);
                }
            }
        }

The issue lies with the Invoice Date and Post Period in the original SO itself - it will follow the date and period based on the Order Date when Prepare Invoice button is pressed:

 

This will prevent the invoice from being saved if the previous period is already closed.

 

How do I ensure that the Invoice Date and Post Period will reflect the same value as the one in SO Invoice?

5 replies

Forum|alt.badge.img
  • Jr Varsity I
  • 27 replies
  • March 27, 2025

The most elegant solution would likely be overriding the original method that is used, to feed the date directly, to ensure the logic is tied in and any other fields that may be affected reflect the correct date as well. The less elegant way you could consider is overriding the prepareinvoice method and tacking on logic update the fields that you want after it runs, but the first option would probably be best.


Forum|alt.badge.img+8
  • Captain II
  • 389 replies
  • April 2, 2025

HI ​@ericklasimin61 

 

When we create an invoice it automatically defaults to the current post period and today’s date.

Are you not experiencing this?

 

Aleks


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 51 replies
  • April 4, 2025
josiahl64 wrote:

The most elegant solution would likely be overriding the original method that is used, to feed the date directly, to ensure the logic is tied in and any other fields that may be affected reflect the correct date as well. The less elegant way you could consider is overriding the prepareinvoice method and tacking on logic update the fields that you want after it runs, but the first option would probably be best.

Hi ​@josiahl64 , thank you for your response. I have never overridden any built-in methods since it may cause unexpected behavior to the process flow. Do you mind pointing me in the right direction on where I may refer to this topic?


Forum|alt.badge.img
  • Author
  • Jr Varsity III
  • 51 replies
  • April 4, 2025
aiwan wrote:

HI ​@ericklasimin61 

 

When we create an invoice it automatically defaults to the current post period and today’s date.

Are you not experiencing this?

 

Aleks

Hi ​@aiwan , creating an invoice will default the current post period and today’s date, but what I am looking for is to have the Invoice Date and Post Period in the original SO (CM type) to be of current date and period upon pressing the Prepare Invoice button.


Forum|alt.badge.img
  • Jr Varsity I
  • 27 replies
  • April 7, 2025
ericklasimin61 wrote:
josiahl64 wrote:

The most elegant solution would likely be overriding the original method that is used, to feed the date directly, to ensure the logic is tied in and any other fields that may be affected reflect the correct date as well. The less elegant way you could consider is overriding the prepareinvoice method and tacking on logic update the fields that you want after it runs, but the first option would probably be best.

Hi ​@josiahl64 , thank you for your response. I have never overridden any built-in methods since it may cause unexpected behavior to the process flow. Do you mind pointing me in the right direction on where I may refer to this topic?

The simplest way if you know which method you are trying to override is to create a customization, go to code>>add and create a graph extension, then click the override method button to select the method you would like to override and add in your custom code.

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings