Question

How to avoid updating the shipping address if the Override address checkbox is already checked on the screen

  • 19 September 2023
  • 15 replies
  • 197 views

Userlevel 1
Badge

Hello Everyone,

 

When the Business account is selected on the opportunity screen, the 'SHIP-TO Address' panel address fields on the shipping tab will be updated with business account address.

We will, however, create an Opportunity without a business account and add the address by clicking the override address checkbox. The business account will then be assigned to the opportunity later.

Even if the override address checkbox is ticked, Acumatica will override the currently available address with the selected business account address.

We wanted to restrict this functionality such that the address from the business account is not updated if the override address checkbox is ticked.

The "OpportunityAddressID" field of the CROpportunity DAC handles this logic with the "CROpportunityAddressAttribute" class, which is inherited from the "CRAddressAttribute" and "AddressAttribute" classes.

We tried to change/override the methods in these classes, however we were unable to access already entered data of the address fields in these classes. If the override address checkbox was checked, we wanted to skip the address of a business account.
 

public class OpportunityMaint_Extension : PXGraphExtension<PX.Objects.CR.OpportunityMaint>
{
#region Event Handlers
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXRemoveBaseAttributeAttribute(typeof(CROpportunityAddressAttribute))]
[TestCROpportunityAddressAttribute(typeof(Select<Address, Where<True, Equal<False>>>))]

protected virtual void CROpportunity_OpportunityAddressID_CacheAttached(PXCache sender)
{
}
#endregion
}

I tried to access current data on DefaultRecord method but the object (targetAddress from below screenshot) is returning null always.

 

 

Anyone have a suggestion/idea for implementing this?

Thanks in advance.


15 replies

Userlevel 6
Badge +3

Hi @rajeshvemunoori31,

I spent a little time to solve this problem with an attribute, and I learned a private function in CPOpportunitycontactAddressExt calls SharedRecordAttribute.DefaultRecord function directly, and we are not able to override it.
However, I have found a less elegant, but working way to keep your shipping address:

    public class OpportunityMaint_Extension : PXGraphExtension<OpportunityMaint>
{
public virtual void _(Events.FieldUpdated<CROpportunity.bAccountID> e, PXFieldUpdated baseMethod)
{
if (!(e.Row is CROpportunity row)) return;

int? oldShipAddressID = null;
if (Base.Shipping_Address.Current?.OverrideAddress == true)
oldShipAddressID = row.ShipAddressID;

baseMethod.Invoke(e.Cache, e.Args);

if (oldShipAddressID != null)
row.ShipAddressID = oldShipAddressID;
}
}

 

Badge +11

I spent some time on this and couldn't figure out where it was being updated.

Userlevel 1
Badge

Hello @Zoltan Febert and @darylbowman 

Thank you for looking into this.

@Zoltan Febert I tried the above field updated event, but it still does not work, and the address is being updated with the business account address. 

 

 

 

Userlevel 6
Badge +3

Hi @rajeshvemunoori31  It is weird, I tested it on my local instance. Can you share your entire class with us? What Acumatica version do you use?

Userlevel 1
Badge

@Zoltan Febert 

I'm using the 23R1 version (23.101.0071) and have no other logic in the graph extension except this event.

  1. Create an opportunity without a business account value.
  2. Check the override checkbox and add address values on the ship-to address panel and save.
  3. Add a business account to the opportunity now. At this point, the address is being updated using business account data rather than current address data.

 

Userlevel 6
Badge +3

@rajeshvemunoori31, I checked it again, it is still working on my end. @darylbowman, do you have time to do a quick test?

Badge +11

It doesn’t work for me in 23.102.0042

Badge +11

This should work:

public class OpportunityMaint_Extension : PXGraphExtension<OpportunityMaint>
{
public static bool IsActive() => true;

// Stores the AddressID of the overriden shipping address
private int? OverriddenShipAddressID { get; set; }

public virtual void _(Events.FieldUpdated<CROpportunity.bAccountID> e, PXFieldUpdated b)
{
if (!(e.Row is CROpportunity row)) return;

var opportunityGraph = e.Cache.Graph as OpportunityMaint;

// If the shipping address is overriden, store the AddressID
if (opportunityGraph.Shipping_Address.Current?.OverrideAddress ?? false)
OverriddenShipAddressID = row.ShipAddressID;

b?.Invoke(e.Cache, e.Args);
}

protected virtual void _(Events.FieldUpdated<CRShippingAddress, CRShippingAddress.overrideAddress> e, PXFieldUpdated b)
{
if (!(e.Row is CRShippingAddress row)) return;

b?.Invoke(e.Cache, e.Args);

// If the shipping address is not overriden but it was, override it again
if (!(row.OverrideAddress ?? false) && OverriddenShipAddressID is object)
{
e.Cache.SetValue<CRShippingAddress.overrideAddress>(row, true);

var opportunityGraph = e.Cache.Graph as OpportunityMaint;
opportunityGraph.Opportunity.SetValueExt<CROpportunity.shipAddressID>(opportunityGraph.Opportunity.Current, OverriddenShipAddressID);

// Reset the stored AddressID
OverriddenShipAddressID = null;
}
}
}

 

Userlevel 1
Badge

Hello @darylbowman 

I tried with above logic but it is still not working.

Badge +11

 

@Zoltan Febert  - Return the favor? 🤓

Userlevel 6
Badge +3

@darylbowman Your solution doesn’t work here, but mine does 😁

 

Userlevel 7
Badge

Hi @rajeshvemunoori31 were you able to find a solution? Thank you!

Userlevel 4
Badge

@Zoltan Febert @darylbowman Is there a way to do this using low code/no code? This “glitch” of overriding the override is one of many reasons we had to push back implementing CRM. 95% of the time our ship to address will be different from the business account address, and because we are a subcontractor we will seldom know who the awarded business account will be when the opportunity and project quote are set up. Based on some other posts I was able to get the override project address box under the project quote to be checked by default, however I couldn’t get it to work on the opportunities side, and as soon as the business account is entered, under either the Opportunity or Project Quote, the override gets overridden. Unfortunately, I don’t know enough about SQL to understand how to make your recommendations above work, or where under customizations to enter.  I appreciate any help or direction you can provide. Thank you! 

Badge +11

If you can't figure it out yourself, I suggest you request help from your VAR or another qualified individual.

Defaulting a field can often be done with low/no code, but not much more.

Userlevel 4
Badge

@darylbowman Thanks for your response. Unfortunately, this is something that we have been trying to figure out for months. Our VAR opened a case with Acumatica over the summer and we haven’t heard anything on it. We upvoted where someone else posted this being an issue in the community, and I just happened to come across this post yesterday as I was searching for something else. It seems like this is starting to become an issue for more users.

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