Skip to main content

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);
        bPXOverride]
        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!

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!!


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