Skip to main content
Question

Difficulty Modifying/Inserting Records in Persist()

  • June 2, 2021
  • 0 replies
  • 1016 views

Forum|alt.badge.img

I am new to Acumatica development. I am currently working on creating a Screen (and corresponding Graph) that interacts with PR objects.

One of my first tasks is to insert a new PR Employee based on the data of an existing EPEmployee. I have overridden the `Persist()` method and based my logic largely on the `InsertForImport()` method in `PX.Objects.PR.PREmployeePayrollSettingsMaint` .Relevant parts of my graph follows:
 

using System;
using PX.Data;
using PX.Data.BQL.Fluent;
using PX.Objects.PR;
using PX.Objects.GL;
using PX.Objects.EP;

namespace PRImport
{
public class PRImportNew : PXGraph<PRImportNew>
{

public PXSave<PREmployee> Save;
public PXCancel<PREmployee> Cancel;
public PXInsert<PREmployee> Insert;


public SelectFrom<PREmployee>.
InnerJoin<Branch>.
On<PREmployee.parentBAccountID.IsEqual<Branch.bAccountID>>.
Where<MatchWithBranch<Branch.branchID>.
And<MatchWithPayGroup<PREmployee.payGroupID>>>.View PayrollEmployee;
public PXFilter<CreateEditPREmployeeFilter> CreateEditPREmployeeFilter;

public override void Persist()
{
var epGraph = PXGraph.CreateInstance<EPEmployeeSelectGraph>();
EPEmployee employee = epGraph.Employee.SelectSingle(CreateEditPREmployeeFilter.Current.BAccountID);
if (employee != null)
{
Caches[typeof(EPEmployee)] = epGraph.Caches[typeof(EPEmployee)];
PREmployee prEmployee = PayrollEmployee.Extend(employee);
prEmployee.EmployeeClassID = CreateEditPREmployeeFilter.Current.EmployeeClassID;
prEmployee.PaymentMethodID = CreateEditPREmployeeFilter.Current.PaymentMethodID;
prEmployee.CashAccountID = CreateEditPREmployeeFilter.Current.CashAccountID;
// var res = PayrollEmployee.Insert(prEmployee);
PayrollEmployee.Update(prEmployee);
base.Persist();
}
else
{
throw new Exception($"Employee not found! Account ID {CreateEditPREmployeeFilter.Current.BAccountID}");
}
}


}
}

Whenever I attempt to insert a record (using the `CreateEditPREmployeeFilter` object), I receive the following error:

```
Error: Inserting  'Employee' record raised at least one error. Please review the errors. Error: 'Legal Name' cannot be empty. Error: 'Employee Name' cannot be empty. Error: 'Employee Class' cannot be empty. Error: 'Department' cannot be empty. Error: 'Default Location' cannot be empty. Error: 'Sales Account' cannot be empty. Error: 'Sales Sub.' cannot be empty. Error: 'Cash Discount Account' cannot be empty. Error: 'Cash Discount Sub.' cannot be empty. Error: 'Expense Account' cannot be empty. Error: 'Expense Sub.' cannot be empty. Error: 'Employee ID' cannot be empty. Error: 'Class ID' cannot be empty. Error: 'Payment Method' cannot be empty. Error: 'Cash Account' cannot be empty.
```

However, looking at the `prEmployee` object at the `PayrollEmployee.Update(prEmployee)` line, I see that the the employee is properly populated with these values. Based on my limited experience with Acumatica, it seems that the code in `base.Persist()` is not recognizing the object in the Cache as inserted/updated.

I have tried using both `PayrollEmployee.Update()` (based on the `InsertForImport()` logic in `PX.Objects.PR.PREmployeePayrollSettingsMaint`) and `Insert()`, but both resulted in the same error. `Insert()` returns null, but I receive no errors from that particular function().

Looking at `PayrollEmployee.Cache` it looks like the Inserted value is not correctly populated  (only select fields shown):

 

     AcctCD    null    string
AcctName null string
BAccountID -2147483647 int?
DedSplitType "PRO" string
DefAddressID null int?
DefContactID null int?
DefLocationID null int?

However, the Updated property looks to be correctly populated (only select fields shown)::

        AcctCD    "EP00000006"    string
AcctName "Todd Bloom" string
BAccountID 2896 int?
ClassID "EMPHOURLY" string
DedSplitType "PRO" string
DefAddressID 3207 int?
DefContactID 3209 int?
DefLocationID 3131 int?