Solved

How do I update a custom field in a different DAC to the one specified in FieldUpdated event?

  • 12 October 2023
  • 2 replies
  • 81 views

Userlevel 4
Badge

Hi,

In the Projects screen, a client is wanting to have the description field from the Tasks tab to be copied across to the ‘Task Description’ custom field in the Revenue and Cost Budget tabs.

 

I have code set up from a previous request that copied over the Task ID column to these tabs, so I am just needing to add some additional logic to this code, but I am not sure how to achieve this.

 

The comments in the code starting with ‘ATTEMPT:’ show where I was adding in the logic to try and achieve this.

 

It publishes without any issues, but then when I try it out in the Projects screen, I get the error shown in the image below about an incorrect extension being requested.

 

What would you recommend for my next attempt?

 

Kind regards,

Andrew

 



protected void PMTask_UsrLineCtr_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

var row = (PMTask)e.Row;

PMTaskExt rowExt = row.GetExtension<PMTaskExt>();

// ATTEMPT: Grabbing the DAC extension for the PMRevenueBudget and PMCostBudget DACs
PMBudgetExt budgetExt = cache.GetExtension<PMBudgetExt>(row);

PMTask task = new PMTask();
task.ProjectID = row.ProjectID;
task.TaskID = row.TaskID;
task.Description = row.Description;

var selectCostBudget = new PXSelect<PMCostBudget,
Where<PMCostBudget.projectID, Equal<Required<PMCostBudget.projectID>>,
And<PMCostBudget.projectTaskID, Equal<Required<PMCostBudget.projectTaskID>>,
And<PMCostBudget.type, Equal<GL.AccountType.expense>>>>>(this.Base);

var selectRevenueBudget = new PXSelect<PMRevenueBudget,
Where<PMRevenueBudget.projectID, Equal<Required<PMRevenueBudget.projectID>>,
And<PMRevenueBudget.projectTaskID, Equal<Required<PMRevenueBudget.projectTaskID>>,
And<PMRevenueBudget.type, Equal<GL.AccountType.income>>>>>(this.Base);

bool costBudgetExists = false;
// If task already exists in the Cost Budget column, just update the LineCntr column
foreach (PMCostBudget budget in selectCostBudget.Select(task.ProjectID, task.TaskID))
{
budget.LineCntr = rowExt.UsrLineCtr;
costBudgetExists = true;
selectCostBudget.Update(budget);
}

bool revBudgetExists = false;
// If task already exists in the Cost Budget column, just update the LineCntr column
foreach (PMRevenueBudget budget in selectRevenueBudget.Select(task.ProjectID, task.TaskID))
{
budget.LineCntr = rowExt.UsrLineCtr;
revBudgetExists = true;
selectRevenueBudget.Update(budget);
}


if (!costBudgetExists) {
// Add task to Cost Budget Tab if it doesn't exist
PMCostBudget costBudget = new PMCostBudget();
costBudget.LineCntr = rowExt.UsrLineCtr;
costBudget.ProjectTaskID = task.TaskID;
selectCostBudget.Insert(costBudget);
}

if (!revBudgetExists) {
// Add task to Revenue Budget Tab if it doesn't exist
PMRevenueBudget revBudget = new PMRevenueBudget();
revBudget.LineCntr = rowExt.UsrLineCtr;
revBudget.ProjectTaskID = task.TaskID;

// ATTEMPT: This is how I was aiming to update the custom field with the Task description
budgetExt.UsrDescriptionExt = task.Description;

selectRevenueBudget.Insert(revBudget);
}
}

#endregion
}
}

 

 

icon

Best answer by Zoltan Febert 12 October 2023, 02:59

View original

2 replies

Userlevel 4
Badge

Thanks so much for that Zoltan!

Userlevel 6
Badge +3

Hi @AndrewA,

The error message means you try to get a PMBudgetExt type of extension using a PMTask row. It fails, because the base DAC of PMBudgetExt is PMBudget (I guess), not PMTask.

I added one more line to your code, you need to remove PMTaskExt rowExt = row.GetExtension<PMTaskExt>(); from your code.

      if (!revBudgetExists) {
// Add task to Revenue Budget Tab if it doesn't exist
PMRevenueBudget revBudget = new PMRevenueBudget();
revBudget.LineCntr = rowExt.UsrLineCtr;
revBudget.ProjectTaskID = task.TaskID;

// Get DAC Extension
var budgetExt = revBudget.GetExtension<PMBudgetExt>();

// ATTEMPT: This is how I was aiming to update the custom field with the Task description
budgetExt.UsrDescriptionExt = task.Description;

selectRevenueBudget.Insert(revBudget);
}

 

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