Solved

Getting a UDF set to a value in the Batch table from the APRegister table not saving

  • 18 June 2021
  • 2 replies
  • 50 views

Userlevel 6
Badge +3

I am posting a Bill from the Bills and Adjustments.  There is a UDF UsrExtProjectID being saved in the APRegister table.

When the JE gets posted for that bill, I want to set the UDF with the same name in the Batch table for the corresponding JE created from the bill.

I am overriding the PostBatchProc method in the PostGraph graph.

    public class PostGraph_Extension : PXGraphExtension<PostGraph>
    {

        public delegate void PostBatchProcDelegate(Batch b);
        [PXOverride]
        public virtual void PostBatchProc(Batch b, PostBatchProcDelegate baseMethod)
        {

            baseMethod(b);

 

Here is the section of the code doing the work:

            if (continueProcessingPID)
            {
                //get the Batch for the current transaction
                Batch batch = SelectFrom<Batch>.Where<Batch.batchNbr.IsEqual<@P.AsString>>
                    .View.Select(Base, b.BatchNbr);

                if (batch.Module == "AP")
                {


                    //get the Batch for the current transaction
                    APRegister apRegister = SelectFrom<APRegister>.Where<APRegister.batchNbr.IsEqual<@P.AsString>>
                        .View.Select(Base, b.BatchNbr);

                    APRegisterExt itemAPExt = PXCache<APRegister>.GetExtension<APRegisterExt>(apRegister);

                    if (itemAPExt != null)
                    {
                        BatchExt itemBatchExt = PXCache<Batch>.GetExtension<BatchExt>(batch);

                        itemBatchExt.UsrProjectID = itemAPExt.UsrProjectID;

                        Base.Actions.PressSave();
                    }
                }
            }
Since the Batch table is not part of the method I am overriding, I suspect that is why the change is not being saved. 

I am probably missing a simple line of code but I don’t know what it is.

Any help is greatly appreciated!

icon

Best answer by Naveen Boga 18 June 2021, 18:07

View original

2 replies

Userlevel 7
Badge +17

Hey Joe…
To Update the field in Batch table, you need to create a JournalEntry and do a cache update. Please find the code sample below..

 

if (continueProcessingPID)
            {
                //get the Batch for the current transaction
                Batch batch = SelectFrom<Batch>.Where<Batch.batchNbr.IsEqual<@P.AsString>>
                    .View.Select(Base, b.BatchNbr);

                if (batch != null && batch.Module == "AP")
                {
                    JournalEntry JEGraph = PXGraph.CreateInstance<JournalEntry>();

                    JEGraph.BatchModule.Current = batch;

                    APRegister apRegister = SelectFrom<APRegister>.Where<APRegister.batchNbr.IsEqual<@P.AsString>>
                        .View.Select(Base, b.BatchNbr);

                    APRegisterExt itemAPExt = PXCache<APRegister>.GetExtension<APRegisterExt>(apRegister);

                    if (itemAPExt != null)
                    {
                        BatchExt itemBatchExt = PXCache<Batch>.GetExtension<BatchExt>(batch);

                        itemBatchExt.UsrProjectID = itemAPExt.UsrProjectID;

                        JEGraph.BatchModule.Cache.Update(batch);
                        JEGraph.Save.Press();
                        Base.Actions.PressSave();
                    }
                }
            }

 

Hope this helps!!

Userlevel 6
Badge +3

Thank you Naveen!  That did the trick.You are awesome as usual.  Now I have code to copy/paste the next time I need to do this!  :-)

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved