Skip to main content

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

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