Skip to main content
Answer

Create ReverseTransaction and have some error

  • December 1, 2025
  • 4 replies
  • 32 views

Forum|alt.badge.img+1

Inserting  'GL Batch' record raised at least one error. Please review the errors. The 20-2512 financial period does not exist for the PRODUCTS company.
 

JournalEntry journalEntry = PXGraph.CreateInstance<JournalEntry>();
            PostGraph pg = PXGraph.CreateInstance<PostGraph>();
            journalEntry.ReverseBatchProc(batch);
            journalEntry.BatchModule.SetValueExt<Batch.module>(journalEntry.BatchModule.Current, batch.Module);
            journalEntry.BatchModule.SetValueExt<Batch.dateEntered>(journalEntry.BatchModule.Current, tranDate);
            journalEntry.BatchModule.SetValueExt<Batch.finPeriodID>(journalEntry.BatchModule.Current, finPeriodID);

            PXCache gltrans = journalEntry.Caches[typeof(GLTran)];
            foreach (object gltr in gltrans.Inserted)
            {
                gltrans.SetValueExt<GLTran.module>(gltr, batch.Module);
                gltrans.SetValueExt<GLTran.tranDate>(gltr, tranDate);
                gltrans.SetValueExt<GLTran.finPeriodID>(gltr, finPeriodID);
            }

            if (journalEntry.BatchModule.Current.Status == BatchStatus.Hold)
            {
                journalEntry.BatchModule.Current.Approved = true;
                journalEntry.releaseFromHold.Press();
            }

            journalEntry.Save.Press();

Best answer by aleksandrsechin

@bihalivan15 
Change the format of your finPeriodID value by using the FormatForDisplay method:

var formattedFinPeriodID = PX.Objects.GL.FinPeriods.FinPeriodUtils.FormatForDisplay(finPeriodID);

JournalEntry journalEntry = PXGraph.CreateInstance<JournalEntry>();
PostGraph pg = PXGraph.CreateInstance<PostGraph>();
journalEntry.ReverseBatchProc(batch);
journalEntry.BatchModule.SetValueExt<Batch.module>(journalEntry.BatchModule.Current, batch.Module);
journalEntry.BatchModule.SetValueExt<Batch.dateEntered>(journalEntry.BatchModule.Current, tranDate);
journalEntry.BatchModule.SetValueExt<Batch.finPeriodID>(journalEntry.BatchModule.Current, formattedFinPeriodID);

PXCache gltrans = journalEntry.Caches[typeof(GLTran)];
foreach (object gltr in gltrans.Inserted)
{
gltrans.SetValueExt<GLTran.module>(gltr, batch.Module);
gltrans.SetValueExt<GLTran.tranDate>(gltr, tranDate);
gltrans.SetValueExt<GLTran.finPeriodID>(gltr, formattedFinPeriodID);
}

if (journalEntry.BatchModule.Current.Status == BatchStatus.Hold)
{
journalEntry.BatchModule.Current.Approved = true;
journalEntry.releaseFromHold.Press();
}

journalEntry.Save.Press();

 

4 replies

Forum|alt.badge.img+1
  • Author
  • Semi-Pro II
  • December 1, 2025

Financial period is opened. GLTran.module = AR


Forum|alt.badge.img+3

Hi ​@bihalivan15 
What is the value of the finPeriodID variable? Consider restructuring its value. It depends on the DAC field attributes, and in most cases it has to be in the following format: “202512”. However, in some cases it has to be in the “122025” format.


Forum|alt.badge.img+1
  • Author
  • Semi-Pro II
  • December 1, 2025

Hi ​@bihalivan15 
What is the value of the finPeriodID variable? Consider restructuring its value. It depends on the DAC field attributes, and in most cases it has to be in the following format: “202512”. However, in some cases it has to be in the “12-2025” format.

 


Forum|alt.badge.img+3

@bihalivan15 
Change the format of your finPeriodID value by using the FormatForDisplay method:

var formattedFinPeriodID = PX.Objects.GL.FinPeriods.FinPeriodUtils.FormatForDisplay(finPeriodID);

JournalEntry journalEntry = PXGraph.CreateInstance<JournalEntry>();
PostGraph pg = PXGraph.CreateInstance<PostGraph>();
journalEntry.ReverseBatchProc(batch);
journalEntry.BatchModule.SetValueExt<Batch.module>(journalEntry.BatchModule.Current, batch.Module);
journalEntry.BatchModule.SetValueExt<Batch.dateEntered>(journalEntry.BatchModule.Current, tranDate);
journalEntry.BatchModule.SetValueExt<Batch.finPeriodID>(journalEntry.BatchModule.Current, formattedFinPeriodID);

PXCache gltrans = journalEntry.Caches[typeof(GLTran)];
foreach (object gltr in gltrans.Inserted)
{
gltrans.SetValueExt<GLTran.module>(gltr, batch.Module);
gltrans.SetValueExt<GLTran.tranDate>(gltr, tranDate);
gltrans.SetValueExt<GLTran.finPeriodID>(gltr, formattedFinPeriodID);
}

if (journalEntry.BatchModule.Current.Status == BatchStatus.Hold)
{
journalEntry.BatchModule.Current.Approved = true;
journalEntry.releaseFromHold.Press();
}

journalEntry.Save.Press();