Hello!
I’m trying to add a new Vendor with the minimum of data but I’m struggling and I don’t understand what I’m doing wrong. This is on Acumatica 2022R1. Can anyone assist?
Here is the code.
There is a bit of hard coding in there at the moment but they are all valid values on my system.
I’m using the DefLocationExt extension to set the values for country and some account codes, these are mandatory fields.
private void CreateVendor(string VendorCD)
{
VendorMaint vendorMaint = PXGraph.CreateInstance<VendorMaint>();
VendorR vendorR = (VendorR)vendorMaint.BAccount.Cache.CreateInstance();
vendorR.AcctCD = VendorCD;
vendorR = vendorMaint.BAccount.Insert(vendorR);
vendorR.VendorClassID = "AAA";
vendorR = vendorMaint.BAccount.Update(vendorR);
vendorR.AcctName = "New Vendor";
vendorR = vendorMaint.BAccount.Update(vendorR);
vendorR.DiscTakenAcctID = 10025;
vendorR.DiscTakenSubID = 501;
vendorR = vendorMaint.BAccount.Update(vendorR);
var extLocation = vendorMaint.GetExtension<VendorMaint.DefLocationExt>();
Address address = (Address)extLocation.DefLocationAddress.Cache.CreateInstance();
address.BAccountID = vendorR.BAccountID;
address.CountryID = "GB";
address = (Address)extLocation.DefLocationAddress.Cache.Insert(address);
PX.Objects.CR.Standalone.Location location = (PX.Objects.CR.Standalone.Location)extLocation.DefLocation.Cache.CreateInstance();
location.VAPAccountID = 10048;
location.VAPSubID = 501;
location.BAccountID = vendorR.BAccountID;
location = (PX.Objects.CR.Standalone.Location)extLocation.DefLocation.Cache.Insert(location);
try
{
vendorMaint.Actions.PressSave();
}
catch (PXException ex )
{
throw;
}
}
and here is the error I get after calling PressSave
There are 2 questions
- What am I doing wrong in my attempt to create a new vendor?
- The error message says ‘Please review the error’. This is fine when using the Acumatica UI, but doesn’t help in code. I’ve checked the PXException object but the InnerException was null and I cannot see other values which look like they would help. Is there a way to see the errors which the main error message is reporting?
Thanks
Steve