Skip to main content
Answer

Error: Inserting 'Location' record raised at least one error. Please review the errors. on Supplier Screen Custom Button

  • May 28, 2025
  • 2 replies
  • 102 views

Forum|alt.badge.img+2

After upgrade, he following button code attached does not work, 

namespace PX.Objects.AP
{
public class VendorMaint_Extension : PXGraphExtension<VendorMaint>
{
#region Event Handlers
public PXSelect<VendorPaymentMethodDetail> dummy_VendorPaymentMethodDetail;

protected void VendorR_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (VendorR)e.Row;

}



public PXAction<VendorR> CreateLocation;
[PXProcessButton]
[PXUIField(DisplayName = "Create Locations")]
protected virtual IEnumerable createLocation(PXAdapter adapter)
{
Vendor vendor = Base.BAccountAccessor.Current;
if (vendor != null && vendor.BAccountID > 0L)
{
// Base.Actions.PressSave();

CR.BAccountExt _acctExt = PXCache<CR.BAccount>.GetExtension<CR.BAccountExt>(vendor);

PXLongOperation.StartOperation(Base, delegate ()
{
Location defaultLocation = PXSelect<
Location,
Where<
Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationID, Equal<Required<Location.locationID>>>>>
.Select(Base, vendor.BAccountID, vendor.DefLocationID);

PXTrace.WriteInformation($"Default Location: {(defaultLocation != null ? $"ID={defaultLocation.LocationID}, CD={defaultLocation.LocationCD}" : "NOT FOUND")}");

PXResultset<PaymentMethod> paymentDetails = PXSelect<PaymentMethod, Where<PaymentMethodExt.usrMAINUseForSupplierBanking, Equal<boolTrue>>>.Select(Base);

List<PaymentMethodDetail> md = SelectFrom<PaymentMethodDetail>
.Where<PaymentMethodDetail.useFor.IsEqual<PaymentMethodDetailUsage.useForVendor>>.View.Select(Base).RowCast<PaymentMethodDetail>().ToList();


foreach (PaymentMethod paymethod in paymentDetails)
{
//first create all the required locations in the system
Location location = PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>.Select(Base, vendor.BAccountID, paymethod.PaymentMethodID);
//create new location
if (location == null && defaultLocation != null)
{

CRLocation clocation = Base.BaseLocations.Insert();
PXTrace.WriteInformation($"Created new Location object");
clocation.BAccountID = vendor.BAccountID;
Base.BaseLocations.Cache.SetValueExt<Location.bAccountID>(clocation, vendor.BAccountID);

clocation.LocationCD = paymethod.PaymentMethodID;
clocation.Descr = paymethod.Descr;

clocation.CARAccountLocationID = defaultLocation.CARAccountLocationID;
clocation.VTaxZoneID = defaultLocation.VTaxZoneID;
clocation.VTaxCalcMode = defaultLocation.VTaxCalcMode;

clocation.OverrideAddress = false;
clocation.OverrideRemitAddress = false;
clocation.OverrideRemitContact = false;
clocation.OverrideContact = false;

clocation.IsAPAccountSameAsMain = true;
clocation.VAPAccountLocationID = vendor.DefLocationID;

clocation.IsAPPaymentInfoSameAsMain = true;
clocation.VPaymentInfoLocationID = clocation.LocationID;
//clocation.VPaymentInfoLocationID = null; // Let system handle it


clocation.VRemitAddressID = defaultLocation.VRemitAddressID;
clocation.VRemitContactID = defaultLocation.VRemitContactID;

clocation.DefAddressID = defaultLocation.DefAddressID;
clocation.DefContactID = defaultLocation.DefContactID;

PXTrace.WriteInformation($"Setting location fields completed");
PXTrace.WriteInformation($"Location Fields Set - BAccountID: {clocation.BAccountID}, LocationCD: {clocation.LocationCD}, Descr: {clocation.Descr}, CARAccountLocationID: {clocation.CARAccountLocationID}, VTaxZoneID: {clocation.VTaxZoneID}, VTaxCalcMode: {clocation.VTaxCalcMode}, OverrideAddress: {clocation.OverrideAddress}, OverrideRemitAddress: {clocation.OverrideRemitAddress}, OverrideRemitContact: {clocation.OverrideRemitContact}, OverrideContact: {clocation.OverrideContact}, IsAPAccountSameAsMain: {clocation.IsAPAccountSameAsMain}, VAPAccountLocationID: {clocation.VAPAccountLocationID}, IsAPPaymentInfoSameAsMain: {clocation.IsAPPaymentInfoSameAsMain}, VPaymentInfoLocationID: {clocation.VPaymentInfoLocationID}, VRemitAddressID: {clocation.VRemitAddressID}, VRemitContactID: {clocation.VRemitContactID}, DefAddressID: {clocation.DefAddressID}, DefContactID: {clocation.DefContactID}");

Base.BaseLocations.Update(clocation);
}

}







try
{
Base.Save.Press();
}
catch (Exception ex)
{

//failed = true;
throw new PXException(ex.Message);
}


});
}
return adapter.Get();
}


public PXAction<VendorR> UpdateBankingDetails;
[PXProcessButton]
[PXUIField(DisplayName = "Update Banking Details")]
protected virtual IEnumerable updateBankingDetails(PXAdapter adapter)
{

Vendor vendor = Base.BAccountAccessor.Current;
if (vendor != null && vendor.BAccountID > 0L)
{
// Base.Actions.PressSave();

CR.BAccountExt _acctExt = PXCache<CR.BAccount>.GetExtension<CR.BAccountExt>(vendor);

if (_acctExt.UsrMAINBankVerified != true)
{
throw new PXSetPropertyException("Bank Details need to be verified first.");
}

PXLongOperation.StartOperation(Base, delegate ()
{
//get all the payment details which need to be updated
// CRLocation defLocation = Base.GetExtension<VendorMaint.DefLocationExt>().DefLocation.SelectSingle();

Location defaultLocation = PXSelect<
Location,
Where<
Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationID, Equal<Required<Location.locationID>>>>>
.Select(Base, vendor.BAccountID, vendor.DefLocationID);

PXResultset<PaymentMethod> paymentDetails = PXSelect<PaymentMethod, Where<PaymentMethodExt.usrMAINUseForSupplierBanking, Equal<boolTrue>>>.Select(Base);


List<PaymentMethodDetail> md = SelectFrom<PaymentMethodDetail>
.Where<PaymentMethodDetail.useFor.IsEqual<PaymentMethodDetailUsage.useForVendor>>.View.Select(Base).RowCast<PaymentMethodDetail>().ToList();

VendorLocationMaint docgraph = PXGraph.CreateInstance<VendorLocationMaint>();


bool updateRequired = false;

foreach (PaymentMethod paymethod in paymentDetails)
{
//first create all the required locations in the system
Location location = PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>.Select(Base, vendor.BAccountID, paymethod.PaymentMethodID);
//create new location
if (location == null && defaultLocation != null)
{
updateRequired = true;
// location = PXCache<Location>.CreateCopy(defaultLocation);
//location = (CR.Location)Base.BaseLocations.Insert();
CRLocation clocation = Base.BaseLocations.Insert();
clocation.BAccountID = vendor.BAccountID;
Base.BaseLocations.Cache.SetValueExt<Location.bAccountID>(clocation, vendor.BAccountID);

clocation.LocationCD = paymethod.PaymentMethodID;
clocation.Descr = paymethod.Descr;


// location.VAPAccountID = defaultLocation.VAPAccountID;
clocation.CARAccountLocationID = defaultLocation.CARAccountLocationID;
clocation.VTaxZoneID = defaultLocation.VTaxZoneID;
clocation.VTaxCalcMode = defaultLocation.VTaxCalcMode;

//location.VPaymentInfoLocationID = vendor.DefLocationID;

clocation.OverrideAddress = false;
clocation.OverrideRemitAddress = false;
clocation.OverrideRemitContact = false;
clocation.OverrideContact = false;



clocation.IsAPAccountSameAsMain = true;
clocation.VAPAccountLocationID = vendor.DefLocationID;

clocation.IsAPPaymentInfoSameAsMain = true;
clocation.VPaymentInfoLocationID = clocation.LocationID;


clocation.VRemitAddressID = defaultLocation.VRemitAddressID;
clocation.VRemitContactID = defaultLocation.VRemitContactID;

clocation.DefAddressID = defaultLocation.DefAddressID;
clocation.DefContactID = defaultLocation.DefContactID;
}

}


if(updateRequired)
{
try
{
Base.Save.Press();
}
catch (Exception ex)
{

//failed = true;
throw new PXException(ex.Message);
}
}



//now update the paymentdetails
foreach (PaymentMethod paymethod in paymentDetails)
{
try
{
updateRequired = false;
docgraph.Clear();
//Check if the location exists or not

Location location = PXSelect<Location, Where<Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>.Select(Base, vendor.BAccountID, paymethod.PaymentMethodID);
if (location != null && (location.IsAPPaymentInfoSameAsMain != false || location.VPaymentMethodID != paymethod.PaymentMethodID))
{
updateRequired = true;
docgraph.Location.Current = location;
location.IsAPPaymentInfoSameAsMain = false;
location.VPaymentMethodID = paymethod.PaymentMethodID;
docgraph.Location.Cache.SetValueExt<Location.vPaymentMethodID>(location, paymethod.PaymentMethodID);

LocationAPPaymentInfo infoLocation = docgraph.APPaymentInfoLocation.Select();
infoLocation.VPaymentMethodID = paymethod.PaymentMethodID;
docgraph.APPaymentInfoLocation.Cache.MarkUpdated(infoLocation);

docgraph.Location.Cache.MarkUpdated(location);
}
// get the Account ID
string AccountNumberDetailID = md.Where(p => p.PaymentMethodID == paymethod.PaymentMethodID && p.Descr == "Account Number").Select(p => p.DetailID).FirstOrDefault();

if (!string.IsNullOrEmpty(AccountNumberDetailID))
{
VendorPaymentMethodDetail _paymentAccountDetails = PXSelect<VendorPaymentMethodDetail, Where<VendorPaymentMethodDetail.bAccountID, Equal<Required<VendorPaymentMethodDetail.bAccountID>>,
And<VendorPaymentMethodDetail.locationID, Equal<Required<VendorPaymentMethodDetail.locationID>>,
And<VendorPaymentMethodDetail.paymentMethodID, Equal<Required<VendorPaymentMethodDetail.paymentMethodID>>,
And<VendorPaymentMethodDetail.detailID, Equal<Required<VendorPaymentMethodDetail.detailID>>>>>>>.Select(Base, vendor.BAccountID, location.LocationID, paymethod.PaymentMethodID, AccountNumberDetailID);


if (_paymentAccountDetails != null)
{
if (_paymentAccountDetails.DetailValue != _acctExt.UsrMAINAccountNumber)
{
_paymentAccountDetails.DetailValue = _acctExt.UsrMAINAccountNumber;
docgraph.PaymentDetails.Cache.SetValueExt<VendorPaymentMethodDetail.detailValue>(_paymentAccountDetails, _acctExt.UsrMAINAccountNumber);
docgraph.PaymentDetails.Current = _paymentAccountDetails;
docgraph.PaymentDetails.Update(_paymentAccountDetails);
updateRequired = true;
}
}
else
{
_paymentAccountDetails = docgraph.PaymentDetails.Insert();
_paymentAccountDetails.BAccountID = vendor.BAccountID;
_paymentAccountDetails.LocationID = location.LocationID;
_paymentAccountDetails.PaymentMethodID = paymethod.PaymentMethodID;
_paymentAccountDetails.DetailID = AccountNumberDetailID;
_paymentAccountDetails.DetailValue = _acctExt.UsrMAINAccountNumber;
updateRequired = true;
}
}

//get the Title of Account ID
string TitleOfAccountDetailID = md.Where(p => p.PaymentMethodID == paymethod.PaymentMethodID && p.Descr == "Title of Account").Select(p => p.DetailID).FirstOrDefault();

if (!string.IsNullOrEmpty(TitleOfAccountDetailID))
{
VendorPaymentMethodDetail _paymentTitleOfAccountDetails = PXSelect<VendorPaymentMethodDetail, Where<VendorPaymentMethodDetail.bAccountID, Equal<Required<VendorPaymentMethodDetail.bAccountID>>,
And<VendorPaymentMethodDetail.locationID, Equal<Required<VendorPaymentMethodDetail.locationID>>,
And<VendorPaymentMethodDetail.paymentMethodID, Equal<Required<VendorPaymentMethodDetail.paymentMethodID>>,
And<VendorPaymentMethodDetail.detailID, Equal<Required<VendorPaymentMethodDetail.detailID>>>>>>>.Select(Base, vendor.BAccountID, location.LocationID, paymethod.PaymentMethodID, TitleOfAccountDetailID);


if (_paymentTitleOfAccountDetails != null)
{
if (_paymentTitleOfAccountDetails.DetailValue != _acctExt.UsrMAINTitleOfAccount)
{
_paymentTitleOfAccountDetails.DetailValue = _acctExt.UsrMAINTitleOfAccount;
docgraph.PaymentDetails.Cache.SetValueExt<VendorPaymentMethodDetail.detailValue>(_paymentTitleOfAccountDetails, _acctExt.UsrMAINTitleOfAccount);
docgraph.PaymentDetails.Current = _paymentTitleOfAccountDetails;
docgraph.PaymentDetails.Update(_paymentTitleOfAccountDetails);
updateRequired = true;
}
}
else
{
_paymentTitleOfAccountDetails = docgraph.PaymentDetails.Insert();
_paymentTitleOfAccountDetails.BAccountID = vendor.BAccountID;
_paymentTitleOfAccountDetails.LocationID = location.LocationID;
_paymentTitleOfAccountDetails.PaymentMethodID = paymethod.PaymentMethodID;
_paymentTitleOfAccountDetails.DetailID = TitleOfAccountDetailID;
_paymentTitleOfAccountDetails.DetailValue = _acctExt.UsrMAINTitleOfAccount;
updateRequired = true;
}
}


//get the Title of Account ID
string BSBNumberDetailID = md.Where(p => p.PaymentMethodID == paymethod.PaymentMethodID && p.Descr == "BSB Number").Select(p => p.DetailID).FirstOrDefault();

if (!string.IsNullOrEmpty(BSBNumberDetailID))
{
VendorPaymentMethodDetail _paymentBSBDetails = PXSelect<VendorPaymentMethodDetail, Where<VendorPaymentMethodDetail.bAccountID, Equal<Required<VendorPaymentMethodDetail.bAccountID>>,
And<VendorPaymentMethodDetail.locationID, Equal<Required<VendorPaymentMethodDetail.locationID>>,
And<VendorPaymentMethodDetail.paymentMethodID, Equal<Required<VendorPaymentMethodDetail.paymentMethodID>>,
And<VendorPaymentMethodDetail.detailID, Equal<Required<VendorPaymentMethodDetail.detailID>>>>>>>.Select(Base, vendor.BAccountID, location.LocationID, paymethod.PaymentMethodID, BSBNumberDetailID);


if (_paymentBSBDetails != null)
{
if (_paymentBSBDetails.DetailValue != _acctExt.UsrMAINBSBNumber)
{
_paymentBSBDetails.DetailValue = _acctExt.UsrMAINBSBNumber;
docgraph.PaymentDetails.Cache.SetValueExt<VendorPaymentMethodDetail.detailValue>(_paymentBSBDetails, _acctExt.UsrMAINBSBNumber);
docgraph.PaymentDetails.Current = _paymentBSBDetails;
//docgraph.PaymentDetails.Cache.MarkUpdated(_paymentBSBDetails);
docgraph.PaymentDetails.Update(_paymentBSBDetails);
updateRequired = true;
}
}
else
{
_paymentBSBDetails = docgraph.PaymentDetails.Insert();
_paymentBSBDetails.BAccountID = vendor.BAccountID;
_paymentBSBDetails.LocationID = location.LocationID;
_paymentBSBDetails.PaymentMethodID = paymethod.PaymentMethodID;
_paymentBSBDetails.DetailID = BSBNumberDetailID;
_paymentBSBDetails.DetailValue = _acctExt.UsrMAINBSBNumber;
updateRequired = true;
}
}


if (updateRequired == true)
{

docgraph.Save.Press();
}

}
catch (Exception ex)
{

//failed = true;
throw new PXException(ex.Message);
}
}
//now set the default banking details for this vendor
PaymentMethod defpaymentDetails = PXSelect<PaymentMethod, Where<PaymentMethodExt.usrMAINDefaultSupplierPaymentMethod, Equal<boolTrue>>>.Select(Base);

if (defpaymentDetails != null && defaultLocation.LocationCD != defpaymentDetails.PaymentMethodID)
{
//get the location for the default
Location payDefault = PXSelect<Location,Where< Location.bAccountID, Equal<Required<Location.bAccountID>>,
And<Location.locationCD, Equal<Required<Location.locationCD>>>>>
.Select(Base, vendor.BAccountID, defpaymentDetails.PaymentMethodID);

if (payDefault != null)
{
vendor.DefLocationID = payDefault.LocationID;

Base.BAccountAccessor.Update((VendorR)vendor);
Base.Save.Press();
}
}
});
}
return adapter.Get();
}
#endregion
}
}

I tried not setting VPaymentInfoLocationID a value in the ‘Create Locations’ button but that does not work either. I also logged the trace below for a test record: 

Trace:
Default Location: ID=34979, CD=100VWMGMT
Created new Location object
Setting location fields completed
Location Fields Set - BAccountID: 10574, LocationCD: AUANZDC, Descr: AU ANZ Bank, CARAccountLocationID: 34979, VTaxZoneID: DOMESTIC, VTaxCalcMode: T, OverrideAddress: False, OverrideRemitAddress: False, OverrideRemitContact: False, OverrideContact: False, IsAPAccountSameAsMain: True, VAPAccountLocationID: 34979, IsAPPaymentInfoSameAsMain: True, VPaymentInfoLocationID: , VRemitAddressID: 20293, VRemitContactID: 20330, DefAddressID: 20293, DefContactID: 20330

Location Fields Set - BAccountID: 10574, LocationCD: AUBENDC, Descr: AU Bendigo Bank, CARAccountLocationID: 34979, VTaxZoneID: DOMESTIC, VTaxCalcMode: T, OverrideAddress: False, OverrideRemitAddress: False, OverrideRemitContact: False, OverrideContact: False, IsAPAccountSameAsMain: True, VAPAccountLocationID: 34979, IsAPPaymentInfoSameAsMain: True, VPaymentInfoLocationID: , VRemitAddressID: 20293, VRemitContactID: 20330, DefAddressID: 20293, DefContactID: 20330

Location Fields Set - BAccountID: 10574, LocationCD: AUBSADC, Descr: AU Bank of SA, CARAccountLocationID: 34979, VTaxZoneID: DOMESTIC, VTaxCalcMode: T, OverrideAddress: False, OverrideRemitAddress: False, OverrideRemitContact: False, OverrideContact: False, IsAPAccountSameAsMain: True, VAPAccountLocationID: 34979, IsAPPaymentInfoSameAsMain: True, VPaymentInfoLocationID: , VRemitAddressID: 20293, VRemitContactID: 20330, DefAddressID: 20293, DefContactID: 20330

Location Fields Set - BAccountID: 10574, LocationCD: AUCBADC, Descr: AU Commonwealth Bank of Australia, CARAccountLocationID: 34979, VTaxZoneID: DOMESTIC, VTaxCalcMode: T, OverrideAddress: False, OverrideRemitAddress: False, OverrideRemitContact: False, OverrideContact: False, IsAPAccountSameAsMain: True, VAPAccountLocationID: 34979, IsAPPaymentInfoSameAsMain: True, VPaymentInfoLocationID: , VRemitAddressID: 20293, VRemitContactID: 20330, DefAddressID: 20293, DefContactID: 20330

Location Fields Set - BAccountID: 10574, LocationCD: AUSTGDC, Descr: AU St George Bank Format Direct Credit, CARAccountLocationID: 34979, VTaxZoneID: DOMESTIC, VTaxCalcMode: T, OverrideAddress: False, OverrideRemitAddress: False, OverrideRemitContact: False, OverrideContact: False, IsAPAccountSameAsMain: True, VAPAccountLocationID: 34979, IsAPPaymentInfoSameAsMain: True, VPaymentInfoLocationID: , VRemitAddressID: 20293, VRemitContactID: 20330, DefAddressID: 20293, DefContactID: 20330

Location Fields Set - BAccountID: 10574, LocationCD: AUSUNDC, Descr: AU Suncorp Bank, CARAccountLocationID: 34979, VTaxZoneID: DOMESTIC, VTaxCalcMode: T, OverrideAddress: False, OverrideRemitAddress: False, OverrideRemitContact: False, OverrideContact: False, IsAPAccountSameAsMain: True, VAPAccountLocationID: 34979, IsAPPaymentInfoSameAsMain: True, VPaymentInfoLocationID: , VRemitAddressID: 20293, VRemitContactID: 20330, DefAddressID: 20293, DefContactID: 20330

Location Fields Set - BAccountID: 10574, LocationCD: AUWBCDC, Descr: AU Westpac Banking, CARAccountLocationID: 34979, VTaxZoneID: DOMESTIC, VTaxCalcMode: T, OverrideAddress: False, OverrideRemitAddress: False, OverrideRemitContact: False, OverrideContact: False, IsAPAccountSameAsMain: True, VAPAccountLocationID: 34979, IsAPPaymentInfoSameAsMain: True, VPaymentInfoLocationID: , VRemitAddressID: 20293, VRemitContactID: 20330, DefAddressID: 20293, DefContactID: 20330

Error: Inserting 'Location' record raised at least one error. Please review the errors.

I have attached the customization for the VendorMaint graph as well, any help would be appreciated thank you!

Best answer by TharidhiP

Hi All, this error was resolved by adding the following mandatory field setting in both actions:

 clocation.LocType = defaultLocation.LocType;
clocation.Status = defaultLocation.Status;

Hope this helps, thank you!

2 replies

Forum|alt.badge.img+2
  • Author
  • Pro III
  • Answer
  • June 2, 2025

Hi All, this error was resolved by adding the following mandatory field setting in both actions:

 clocation.LocType = defaultLocation.LocType;
clocation.Status = defaultLocation.Status;

Hope this helps, thank you!


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • June 2, 2025

Thank you for sharing your solution with the community ​@TharidhiP!