Solved

Copy into cost budget from new screen

  • 28 April 2021
  • 1 reply
  • 14 views

I have created a new form tab screen(Project Sub Tasks) which consists of two tabs, Bill of Quantities and Sub Contractor quotes.

What I would like to achieve is, when I have added a new record to one of the tabs, to write it to the project’s cost budget it’s associated with.
 

I have tried the following code:

        // 1. Create an instance of the BLC (graph)
        ProjectEntry graph = PXGraph.CreateInstance<ProjectEntry>();

        protected void _(Events.FieldUpdated<PMBillOfQuantity, PMBillOfQuantity.amount> e)
        {

            var row = (PMBillOfQuantity)e.Row;

            // 2. Create an instance of the DAC, set key field values (besides the ones whose values are generated by the system),
            //    and insert the record into the cache
            PMCostBudget CB = new PMCostBudget();
            CB.AccountGroupID = 35;
            CB = graph.CostBudget.Insert(CB);

            // 3. Set non-key field values and update the record in the cache
            CB.Amount = row.Amount;
            CB.Description = row.Description;

            CB = graph.CostBudget.Update(CB);
        }

 

Any help would be greatly appreciated

icon

Best answer by Cesar Betances 28 April 2021, 20:18

After reviewing your code snippet provided I noticed a couple of things to be fixed(or added), see below code snippet for guidance:

 

...................................................

           // 1. Create an instance of the BLC (graph)
            ProjectEntry graph = PXGraph.CreateInstance<ProjectEntry>();

 

            // 1. Set current document for the instantiated graph (Selecting a record to work with)
            graph.Project.Current = graph.Project
                                   .Search<PMProject.contractCD>("SOMEPROJECTID", "P");   // Use Key fields of the DAC you are trying to select a record from


            // 3. Create an instance of the DAC, set key field values (besides the ones whose values are generated by the system),
            //    and insert the record into the cache
            PMCostBudget CB = new PMCostBudget();
            
            CB.ProjectTaskID = 1690;    //ProjectTaskID is a required field and it needs to be set as well
            CB.AccountGroupID = 34;
            CB = graph.CostBudget.Insert(CB);

            // 4. Set non-key field values and update the record in the cache
            CB.Amount = 22;
            CB.Description = "SOME DESC";

            CB = graph.CostBudget.Update(CB);
           

            // 5. Save/Persist changes if you are not going to redirect users to that screen for them to save changes manually on that screen(graph)
            graph.Persist();

.......................................................

View original

1 reply

After reviewing your code snippet provided I noticed a couple of things to be fixed(or added), see below code snippet for guidance:

 

...................................................

           // 1. Create an instance of the BLC (graph)
            ProjectEntry graph = PXGraph.CreateInstance<ProjectEntry>();

 

            // 1. Set current document for the instantiated graph (Selecting a record to work with)
            graph.Project.Current = graph.Project
                                   .Search<PMProject.contractCD>("SOMEPROJECTID", "P");   // Use Key fields of the DAC you are trying to select a record from


            // 3. Create an instance of the DAC, set key field values (besides the ones whose values are generated by the system),
            //    and insert the record into the cache
            PMCostBudget CB = new PMCostBudget();
            
            CB.ProjectTaskID = 1690;    //ProjectTaskID is a required field and it needs to be set as well
            CB.AccountGroupID = 34;
            CB = graph.CostBudget.Insert(CB);

            // 4. Set non-key field values and update the record in the cache
            CB.Amount = 22;
            CB.Description = "SOME DESC";

            CB = graph.CostBudget.Update(CB);
           

            // 5. Save/Persist changes if you are not going to redirect users to that screen for them to save changes manually on that screen(graph)
            graph.Persist();

.......................................................

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 — 2020  Acumatica, Inc. All rights reserved