Solved

Default Customer Location not updating custom fields

  • 19 November 2021
  • 7 replies
  • 466 views

Hey all,

I have and issue and I am trying to see if anyone else has seen this issue or may know what may be causing this.  We have custom fields on the Locations table and a customization that populates these fields when a new Customer/Vendor Location is added.  In 2020 R1, this customization worked on all added location.   In 2021 R1, this customization works great except for the first initial “Main” Location that gets created automatically when you create a new Customer/Vendor.  Does anyone have any ideas why the automatically created location skips any custom code but all subsequent ones don’t.

Thanks,

 

 

icon

Best answer by jinin 22 November 2021, 17:39

View original

7 replies

Userlevel 4
Badge +2

Here is another tip for others who stumble upon events that are not triggering on CustomerMaint. You may have code triggering on an event on CustomerLocationMaint for Location, such as         public virtual void _(Events.FieldUpdated<Location.cBranchID> e, PXFieldUpdated del) which works fine. 

The reason why the code listed for markusray17 works well is that he is not using the standard Location DAC, he is using 

using Location = PX.Objects.CR.Standalone.Location;

You will find in the code repository that they refer to CRLocation, which has the usings of 

using CRLocation = PX.Objects.CR.Standalone.Location;

Hope this helps!

 

Userlevel 1
Badge

I used this post to get ideas on how to do something similar.  My code sets the default SiteID in the Location table based on the postal code entered. I created a method that uses a table that I created that assigns the warehouse based on the first 3 digits of the zip code.  The method returns a list of warehouse SiteIDs in order of closest to farthest.  It also checks if the new zip code is closer do a different warehouse and sends a popup asking to make the change to the new warehouse.

I did get my code to work using the FieldUpdated event in the CustomerMaint_Extension.  I had to use CRLocation as mentioned by markusray17.  Similar code is also in CustomerLocationMaint to handle changes made under the location tab.

Thought this might help someone.

Code:

 

using CRLocation = PX.Objects.CR.Standalone.Location;

protected void Address_PostalCode_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
    Address row = (Address)e.Row;
    if (row != null && row.PostalCode != null)
    {

        CustomerLocationMaint graph = PXGraph.CreateInstance<CustomerLocationMaint>();

        Customer cust = Base.CurrentCustomer.Current;
        CRLocation loc = Base.BaseLocations.Current;
        if (loc != null)
        {
            string postalCode = row.PostalCode;
            string classID = cust.CustomerClassID;
            var priorityList = ARMethods.getWhseByPostalCode(postalCode, classID);
            if (priorityList[0] != null)
            {
                if (loc.CSiteID == null || loc.CSiteID == 0)
                {
                    loc.CSiteID = priorityList[0];
                    Base.Caches[typeof(CRLocation)].Update(loc);
                }
                else if (loc.CSiteID != priorityList[0])
                {
                    INSite oldSite = INSite.PK.Find(Base, loc.CSiteID);
                    INSite newSite = INSite.PK.Find(Base, priorityList[0]);
                    string message = $"Current RDC " + oldSite.SiteCD + " does not match recommended site " + newSite.SiteCD + ", do you want to change to the recommended site?";
                    WebDialogResult result = Base.CurrentCustomer.Ask(PX.Objects.CN.Common.Descriptor.SharedMessages.Warning, message, MessageButtons.YesNoCancel);
                    if (result.IsPositive())
                    {
                        loc.CSiteID = priorityList[0];
                        Base.Caches[typeof(CRLocation)].Update(loc);
                    }
                }
            }
        }
    }
}

Userlevel 5
Badge +1

@mgygi76 It depends on what event and how you have written the code to populate the custom fields. So, it would be helpful for us to review, if you can share the piece of code that you have written to populate the custom fields.

 

 

Userlevel 6
Badge +5

Tested on 2021 R1 Build 21.110.0032 and I was getting debugging breaks on the default inserted location.

using PX.Data;
using PX.Objects.AR;
using Location = PX.Objects.CR.Standalone.Location;

namespace Temp
{
public class CustomerMaintExt : PXGraphExtension<CustomerMaint>
{
public static bool IsActive() => true;

public void _(Events.RowInserting<Location> e)
{
//Insert Code Here
}

}
}

 

Userlevel 7
Badge +11

Hi @mgygi76 

We can try the below approach as well. When we save the location, get the details from the Default location and assign to the respective fields.

Please review the below sample.
 

 public class KNMCCustomerLocationMaintExtn : PXGraphExtension<CustomerLocationMaint>
    {
        public static bool IsActive() { return true; }

        #region Action
        [PXOverride]
        public void Persist(Action del)
        {
            if (Base.LocationCurrent.Cache.GetStatus((object)Base.LocationCurrent.Current) == PXEntryStatus.Inserted)
            {
                CustomerMaint customerGraph = PXGraph.CreateInstance<CustomerMaint>();
                customerGraph.CurrentCustomer.Current = PXSelect<Customer, Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>.Select(Base, Base.LocationCurrent.Current.BAccountID);

                if (customerGraph.CurrentCustomer.Current != null)
                {
                    var defLocationExt = customerGraph.GetExtension<DefLocationExt>();
                    defLocationExt.DefLocation.Current = defLocationExt.DefLocation.Select();                  

                    Base.LocationCurrent.Current.CShipTermsID = defLocationExt.DefLocation.Current?.CShipTermsID;
                    Base.LocationCurrent.Current.CCarrierID = defLocationExt.DefLocation.Current?.CCarrierID;
                    Base.LocationCurrent.Current.CTaxZoneID = defLocationExt.DefLocation.Current?.CTaxZoneID;
                    Base.LocationCurrent.Cache.Update(Base.LocationCurrent.Current);
                }
            }

            del.Invoke();

        }

    }
 

Userlevel 7
Badge

Thank you for sharing this tip with the community @skalb11!

I have a custom function that does a bunch of lookups and assigns the values but the problem isn’t in the code that function.  I have linked this function to different events on the Location table (field updating, row inserting, etc.).  I have put a couple examples where I have these updates.  I cannot get Acumatica to break on any of these events on that first automatic “Main” Location creation but it does on any user created one.  You can even go into that default location after its been created, change the values and then these events will fire. UpdateLocationTerritory is the function that sets the custom field values.

 

protected void _(Events.RowInserting<Location> eventHandler)
        {
            Location row = eventHandler.Row;
            if (row is null) return;

            UpdateLocationTerritory(eventHandler.Cache.Graph, row);
        }

 

 protected void _(Events.FieldUpdated<Address, Address.postalCode> eventHandler)
        {
            /*
                Updates the SalesTerritoryCD on the Location when
                the Address PostalCode changes.
            */

            Address row = eventHandler.Row;
            Location location = Base.Location.Current;

            if (row is null || location is null)
                return;

            UpdateLocationTerritory(eventHandler.Cache.Graph, location);
        }

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