Solved

How do I populate a field from one DAC with the value of a custom field from another DAC?

  • 5 December 2022
  • 3 replies
  • 615 views

Userlevel 4
Badge

Hi,

I have created a new custom field called LineCtr   (Line Counter) to the PMTask DAC, and I want the value that a user enters in this field to appear in the LineCntr field that is in the PMRevenueBudget column called LineCntr (Line Counter).

In the Projects screen, the custom field I have created is in the Tasks tab, and the field I want to update is in the Revenue Budget tab. Below is an example of how the custom field would be used.

 

And this is the Revenue Budget tab:

 

In the Revenue Budget tab, the Project Task is added via a selector. Currently, my custom field is displayed as a column in the selector so that the user can be sure what number they are going to be adding to the LineCntr column. As shown below, this is how the selector will look:

 

What I would like to happen is, when a user selects a row from this selector, the LineCtr column that is shown in the selector above should be added to the LineCntr column that can be seen in the Revenue Budget tab.

What I am having trouble figuring out is how to do this when the fields I need are in separate DACs.

The DAC info of the fields are shown below:

Here is the custom field I have created:

 

 

Here is the field info for the selector field:

 

And here is the info for the LineCntr field I am wanting to update:

 

I was trying to use PXSelect to grab the relevant custom field value but wasn’t sure how to structure it properly in the code to get the right result.

Any assistance on what I can try next would be greatly appreciated! Let me know if I can supply any further information on this.

 

Thanks,

Andrew

icon

Best answer by AndrewA 23 December 2022, 04:48

View original

3 replies

Userlevel 4
Badge

Nevermind, I managed to get it working, all good now.

protected void PMTask_UsrLineCtr_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

var row = (PMTask)e.Row;

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

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

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);


foreach (PMCostBudget budget in selectCostBudget.Select(task.ProjectID, task.TaskID))
{
budget.LineCntr = rowExt.UsrLineCtr;
selectCostBudget.Update(budget);

}

foreach (PMRevenueBudget budget in selectRevenueBudget.Select(task.ProjectID, task.TaskID))
{
budget.LineCntr = rowExt.UsrLineCtr;
selectRevenueBudget.Update(budget);

}

}

 

Userlevel 4
Badge

Adding an update to my above answer. The code in my previous answer is good for updating existing rows, however it didn't handle adding a new row if an item doesn't already exist.

The code below is the same as the above, just with two additional sections before the for loops for adding the new rows if needed.

protected void PMTask_UsrLineCtrNew_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{

var row = (PMTask)e.Row;

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

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

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);

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

// Add task to Revenue Budget Tab if it doesn't exist
PMRevenueBudget revBudget = new PMRevenueBudget();
revBudget.LineCntr = rowExt.UsrLineCtrNew;
revBudget.ProjectTaskID = task.TaskID;
selectRevenueBudget.Insert(revBudget);

// 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.UsrLineCtrNew;
selectCostBudget.Update(budget);
}

// 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.UsrLineCtrNew;
selectRevenueBudget.Update(budget);
}

}

#endregion
}
}

 

Userlevel 7
Badge

Thank you @AndrewA for sharing this update with the community!

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