'Add an additional line on the grid

I am looking for help, I hope I can solve this problem.

I've created a new screen and I'm filtering all the Revalue Accounts information.

With this screen, what I want to do is insert and at the same time add an additional new line within the grid.

Here is my new created screen and the button that inserts GLTran

enter image description here

I am attaching an image where I want the line to be added at insert time

enter image description here

Here I share code that I have and it does not work for the additional line.

   private void CreateDNGL(Batch batch)

    {
        var graph = PXGraph.CreateInstance<JournalEntry>();

        if (graph.BatchModule.Current == null)
        {
            Batch cmbatch = new Batch();

            cmbatch.BranchID = batch.BranchID;
            cmbatch.Module = batch.Module;
            cmbatch.Status = "U";
            cmbatch.AutoReverse = true;
            cmbatch.Released = true;
            cmbatch.Hold = false;
            cmbatch.CuryDebitTotal = batch.CuryDebitTotal;
            cmbatch.CuryCreditTotal = batch.CuryCreditTotal;
            cmbatch.FinPeriodID = batch.FinPeriodID;
            cmbatch.CuryID = batch.CuryID;
            cmbatch.CuryInfoID = batch.CuryInfoID;
            cmbatch.DebitTotal = batch.DebitTotal;
            cmbatch.CreditTotal = batch.CreditTotal;
            cmbatch.Description = "Head new insert";
            cmbatch = graph.BatchModule.Insert(cmbatch);
        }
        foreach (GLTran item in PXSelect<GLTran,
            Where<GLTran.module, Equal<Required<GLTran.module>>,
            And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(this, batch.Module, batch.BatchNbr))
        {
            GLTran tran = new GLTran();
            tran.SummPost = item.SummPost;
            tran.ZeroPost = false;
            tran.DebitAmt = item.DebitAmt;
            tran.CreditAmt = item.CreditAmt;
            tran.CuryDebitAmt = item.CuryDebitAmt;
            tran.CuryCreditAmt = item.CuryCreditAmt;
            tran.AccountID = item.AccountID;
            tran.SubID = item.SubID;
            tran.LineNbr = item.LineNbr;
            tran.LedgerID = item.LedgerID;
            tran.TranType = item.TranType;
            tran.TranClass = item.TranClass;
            tran.RefNbr = string.Empty;
            tran.FinPeriodID = item.FinPeriodID;
            tran.TranDesc = "Test detail";
            tran.Released = true;
            tran.ReferenceID = item.ReferenceID;
            tran = graph.GLTranModuleBatNbr.Insert(tran);

            Account account = PXSelect<Account, Where<Account.accountID,
       Equal<Required<Account.accountID>>>>.Select(graph, item.AccountID);
            xLocEquivalAcct equivalAcct = PXSelect<xLocEquivalAcct, Where<xLocEquivalAcct.acctCD,
                                   Equal<Required<xLocEquivalAcct.acctCD>>>>.Select(graph, account.AccountCD);

            if (equivalAcct != null)
            {
                /*here is added for an additional line*/
                var glTran = graph.GLTranModuleBatNbr.Insert();
                graph.GLTranModuleBatNbr.SetValueExt<GLTran.accountID>(glTran, 343567);
                graph.GLTranModuleBatNbr.SetValueExt<GLTran.subID>(glTran, 281);
                glTran.TranDesc = "add extra line";
                if (item.DebitAmt != 0m && item.CreditAmt == 0m)
                {
                    if (batch.Module == BatchModule.CM)
                    {
                        graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyDebitAmt>(glTran, item.CuryDebitAmt);
                        graph.GLTranModuleBatNbr.SetValueExt<GLTran.debitAmt>(glTran, item.DebitAmt);
                    }
                }
                if (item.CreditAmt != 0m && item.DebitAmt == 0m)
                {
                    if (batch.Module == BatchModule.CM)
                    {
                        graph.GLTranModuleBatNbr.SetValueExt<GLTran.curyCreditAmt>(glTran, item.CuryCreditAmt);
                        graph.GLTranModuleBatNbr.SetValueExt<GLTran.creditAmt>(glTran, item.CreditAmt);
                    }
                }
                glTran = graph.GLTranModuleBatNbr.Update(glTran);
            }
        }
        graph.Save.Press();
    }

I hope I was clear with my question.



Solution 1:[1]

This code will create a copy of the originating batch and insert additional lines.

#Warning Your original code was attempting to create a batch that was already released but unposted. I can update my answer to match your requirement but this will break Acumatica work-flow.

Please find code example below :

public class JournalEntryExtension : PXGraphExtension<JournalEntry>
    {
        public PXAction<Batch> CopyCreate;

        //CommitChanges being set to false allows the graph to not be considered dirty when there are errors that we manually show on screen. Case #207998
        [PXButton(CommitChanges = false)]
        [PXUIField(DisplayName = "Copy Create", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update, Enabled = true)]
        protected virtual IEnumerable copyCreate(PXAdapter pxAdapter)
        {
            if (Base.BatchModule.Current != null)
            {
                if (Base.IsDirty)
                {
                    Base.BatchModule.Ask("You must discard your unsaved changes to be able to press this button.", MessageButtons.OK);
                }
                else
                {
                    Batch batch = Base.BatchModule.Current;

                    PXLongOperation.StartOperation(this, () => CreateDNGL(batch));
                }
            }

            return pxAdapter.Get();
        }

        private static void CreateDNGL(Batch batch)
        {
            JournalEntry graph = PXGraph.CreateInstance<JournalEntry>();

            Batch newBatch = PXCache<Batch>.CreateCopy(batch);
            newBatch.NoteID = null;
            newBatch.Description = "Test header";
            newBatch = graph.BatchModule.Insert(newBatch);

            GLTran newTran;

            foreach (GLTran tran in PXSelectReadonly<GLTran,
            Where<GLTran.module, Equal<Required<GLTran.module>>,
            And<GLTran.batchNbr, Equal<Required<GLTran.batchNbr>>>>>.Select(graph, batch.Module, batch.BatchNbr))
            {
                newTran = PXCache<GLTran>.CreateCopy(tran);
                newTran.Module = null;
                newTran.BatchNbr = null;
                newTran.NoteID = null;
                newTran.TranDesc = "Test detail";
                newTran = graph.GLTranModuleBatNbr.Insert(newTran);
            }

            if (true)
            {
                newTran = graph.GLTranModuleBatNbr.Insert();
                newTran.AccountID = 1190;
                newTran.SubID = 467;
                newTran.CuryDebitAmt = 1000;
                newTran.TranDesc = "Additional Line 1";

                newTran = graph.GLTranModuleBatNbr.Update(newTran);

                newTran = graph.GLTranModuleBatNbr.Insert();
                newTran.AccountID = 1190;
                newTran.SubID = 467;
                newTran.CuryCreditAmt = 1000;
                newTran.TranDesc = "Additional Line 2";

                newTran = graph.GLTranModuleBatNbr.Update(newTran);
            }

            graph.Save.Press();
        }
    }

Original Batch :

Original Batch

New Batch :

New Batch

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Joshua Van Hoesen