Solved

The record cannot be saved because at least one error has occurred. Please review the errors.

  • 23 November 2022
  • 10 replies
  • 448 views

Userlevel 4
Badge +1

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

  1. What am I doing wrong in my attempt to create a new vendor?
  2. 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

icon

Best answer by Fernando Amadoz 25 November 2022, 16:03

View original

10 replies

Userlevel 7
Badge +5

An easy way to identify the error is to replace your vendorMaint.Actions.PressSave(); with

throw new PXRedirectRequiredException(“”,vendorMaint); which will redirect you to the screen and you’ll be able to see the error messages in UI.

Userlevel 3
Badge

Vendor Location is a separate graph. First finish saving the Vendor and then try to create the location.

Also note that there are two different Location DACs - one under PX.Objects.CR namespace and another under PX.Objects.CR.Standalone. The Vendor Location graph where you create the location references the PX.Objects.CR namespace. 

 

Userlevel 4
Badge +1

@Dmitrii Naumov Thanks for this advice. I tried using PXRedirectRequiredException, this did redirect me to the Vendor Maint screen and displayed the values I had set but it didn’t show the error messages in the UI. Is there no way to identify the errors from the exception object?

After being redirected I could see that the values I had set using the VendorMaint.DefLocationExt extension had not been set. Would you be able to have a little at that part of the code please? It’s possible I’m trying to use this extension in completely the wrong way. 

@Raj Gopinathan Thank you for commenting. I don’t think it will be possible to save the Vendor before creating the location. When you save the Vendor the business rules require a Country to the entered, and this is part of the default address. 

I did notice that there were two types of Location object and wasn’t sure which to use. extLocation.DefLocation.Cache.CreateInstance() returns the standalone version and so I used this. If I try to cast it to PX.Objects.CR.Location then I get an error.

Userlevel 3
Badge

hmmm, but wouldn’t creating a Vendor Location require the corresponding Vendor ID? Even on screen, you don’t get the option to add a Vendor Location until you have saved the Vendor record.

Userlevel 7
Badge +5

@stephenward03 you’ll need to press ‘Save’ button on the screen and you’ll see the errors

Userlevel 4
Badge +1

@Raj Gopinathan I think we are talking about different fields for the Vendor record.

I’m trying to set the Country field in the Account Address section. Screen shot below 

This field is required before a vendor record can be saved. I thought that using the extension - 
vendorMaint.GetExtension<VendorMaint.DefLocationExt>();
would be the best way to access these fields. Do you know if another way?

Thanks

Steve

Userlevel 4
Badge +1

@Dmitrii Naumov 

I’m afraid that pressing save isn’t displaying the errors for me. 

My code now looks like this. I’ve replaced the PressSave call with PXRedriectQueriedException.

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

try
{
throw new PXRedirectRequiredException(vendorMaint, "" );
//vendorMaint.Actions.PressSave();
}
catch (PXException ex )
{
throw;
}
}

The redirect takes place and I can see my data in the Vendor screen. Notice that the Country has not been set to GB so I must be updating that field in the wrong way. 

When I click on the Save button I receive the error message which says 
“The record cannot be saved because at least one error has occurred. Please review the errors.”
I click OK and then see this:

The field errors don’t appear, much of the data is cleared, except for Vendor ID, and the Save button is now disabled. I know understand why this is happening. Did I throw the exception incorrectly?

Userlevel 5
Badge +2

@stephenward03 

Try this alternative version of your method.

I made some adjustments to adapt it to my local environment, but the relevant aspect is how to obtain access to the defContactAddress.DefAddress data view.

        private void CreateVendorReviewed(string VendorCD)
{
VendorMaint vendorMaint = PXGraph.CreateInstance<VendorMaint>();
VendorR vendorR = new VendorR(); //(VendorR)vendorMaint.BAccount.Cache.CreateInstance();
vendorR.AcctCD = VendorCD;
vendorR = vendorMaint.BAccount.Insert(vendorR);
vendorR.VendorClassID = "GNA";//"AAA";
vendorR = vendorMaint.BAccount.Update(vendorR);
vendorR.AcctName = "New Vendor";
vendorR = vendorMaint.BAccount.Update(vendorR);
vendorR.DiscTakenAcctID = 1149;//10025;
vendorR.DiscTakenSubID = 467;//501;
vendorR = vendorMaint.BAccount.Update(vendorR);

var defContactAddress = vendorMaint.GetExtension<VendorMaint.DefContactAddressExt>();
defContactAddress.DefAddress.Current = defContactAddress.DefAddress.Select();
defContactAddress.DefAddress.Current.CountryID = "GB";
defContactAddress.DefAddress.Update(defContactAddress.DefAddress.Current);


try
{
throw new PXRedirectRequiredException(vendorMaint, "" );
//vendorMaint.Actions.PressSave();
}
catch (PXException ex )
{
throw;
}
}

 

Userlevel 4
Badge +1

@Fernando Amadoz Thanks for your reply. 

I used your DefContactAddressExt code and was able to save the vendor record successfully. 

I’ve spent some time trying to understand how to link what the Element Inspector shows to the graph and graph extensions in the Acumatica source code. It seems clearer now. 

Thank you again. 

Steve

Userlevel 5
Badge +2

thanks for the update @stephenward03 

If my reply helped you to resolve the original post, please remember to accept the answer.

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