I had implemented a custom DAC and screen called prospect vendor. then I need to create a default vendor in the system on a button click. following is the action code.
My issue is the header section of vendor page contains data from vendorR dac, which is extended from Vendor Dac, I try to create a vendor instance and saved it, action runs without error, but data is not saved to Database. when I try to save vendorR instance it gives error. how can save a BAccount instance rated to my vendor via VendorMaint graph object.
public PXAction<ESProspectVendors> CreateVendor;
[PXButton(DisplayOnMainToolbar = true, CommitChanges = true)]
[PXUIField(DisplayName = "Create Vendor", Enabled = true)]
protected virtual IEnumerable createVendor(PXAdapter adapter)
{
ESProspectVendors vendor = ProspectVendorsView.Current;
PXLongOperation.StartOperation(this, delegate
{
SaveVendor(vendor);
});
return adapter.Get();
}
public static void SaveVendor(ESProspectVendors prospectVendor)
{
try
{
PXTrace.WriteInformation($" Action Started :");
VendorR vendorR = new VendorR();
Vendor vendor = new Vendor();
BAccount bAccount = new BAccount();
bAccount.AcctCD =
vendorR.AcctCD = prospectVendor.SupplierCode;
vendorR.VendorClassID = prospectVendor.VendorClassID;
vendor.AcctCD = prospectVendor.SupplierCode;
vendor.VendorClassID = prospectVendor.VendorClassID;
vendor.LegalName = prospectVendor.SupplierName;
vendorR.VStatus = "A";
vendor.AcctName = prospectVendor.BankName;
var vendorGraph = PXGraph.CreateInstance<VendorMaint>();
vendorGraph.CurrentVendor.Insert(vendor);
vendorGraph.Actions.PressSave();
//vendorGraph.BAccountAccessor.Insert(bAccount);
vendorGraph.Actions.PressSave();
var prospectVendorGraph = PXGraph.CreateInstance<ESProspectVendorMaint>();
prospectVendor.DefaultVendorCD = vendorR.AcctCD;
prospectVendorGraph.ProspectVendorsView.Update(prospectVendor);
prospectVendorGraph.Actions.PressSave();
PXTrace.WriteInformation($" Action Completed :");
}
catch (Exception ex)
{
PXTrace.WriteInformation($" Error : {ex.Message} - {ex.InnerException.Message}");
}
}