Skip to main content
Solved

AP Quick Check Copy Remit and Contact but keep override

  • December 2, 2021
  • 5 replies
  • 159 views

Forum|alt.badge.img+1

I currently have a customization that makes a copy of a voided quick check and opens in a new popup window for user to make changes before saving the new check.  All is working OK EXCEPT for the remit and contact information.  All of these quick checks have the address/contact overridden (they use a generic vendor).  I want to keep the same contact/remit info but behind the scenes it needs to point to new APAddress and APContact so when they edit these it’s only changing the information for the new check, not the existing.  Currently, when the window pops up, override is unchecked for both contact and address and shows default vendor.  I want the overrides to still be checked and have the values from the check being copied from but when saved I need new records and foreign keys for APAddress and APContact.  What am I doing wrong?

 

Here is some of my code:

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

CurrencyInfo info = PXCache<CurrencyInfo>.CreateCopy(res);

info.CuryInfoID = null;
info.IsReadOnly = false;
info = PXCache<CurrencyInfo>.CreateCopy(graph.currencyinfo.Insert(info));

APQuickCheck payment = new APQuickCheck
{
	DocType = null,
	RefNbr = null,
	CuryInfoID = info.CuryInfoID
};

payment = PXCache<APQuickCheck>.CreateCopy(doc);

// set a bunch of defaults on new payment.....

graph.Document.Insert(payment);

// copy current address and contact
APAddress address = graph.Remittance_Address.Current = graph.Remittance_Address.Select();
APContact contact = graph.Remittance_Contact.Current = graph.Remittance_Contact.Select();

if (address.OverrideAddress == true)
{
	// create new APAddress
	address.OverrideAddress = false;
	address = graph.Remittance_Address.Update(address);
	if (address == null)
	{
		address = graph.Remittance_Address.Current;
	}
	// address.OverrideAddress = true;
	graph.Remittance_Address.Current.OverrideAddress = true;
	graph.Remittance_Address.Update(graph.Remittance_Address.Current);
}

if (contact.OverrideContact == true)
{
	// create new APContact
	contact.OverrideContact = false;
	contact = graph.Remittance_Contact.Update(contact);
	if (contact == null)
	{
		contact = graph.Remittance_Contact.Current;
	}
	graph.Remittance_Contact.Current.OverrideContact = true;
	graph.Remittance_Contact.Update(graph.Remittance_Contact.Current);
}

// loop through APTran, APTaxTran, etc. setting defaults

// show new quick check in popup window
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);

 

Best answer by rjean09

Here is the solution I have now that works.  Sheer trial and error and lots of debugging:

// copy current address and contact
APAddress address = graphCurrent.Remittance_Address.Select();
APContact contact = graphCurrent.Remittance_Contact.Select();

graph.Document.Cache.SetDefaultExt<APQuickCheck.remitAddressID>(payment);
graph.Document.Cache.SetDefaultExt<APQuickCheck.remitContactID>(payment);

graph.Document.Insert(payment);

if (address.OverrideAddress == true)
{

	graph.Remittance_Address.Cache.Clear();
	APAddress newAddress = new APAddress();
	// create new APAddress
	newAddress.OverrideAddress = true;
	newAddress = graph.Remittance_Address.Update(newAddress);
	if (newAddress == null)
	{
		newAddress = graph.Remittance_Address.Current;
		graph.Remittance_Address.Update(newAddress);
	}

	newAddress.VendorAddressID = address.VendorAddressID;
	newAddress.VendorID = address.VendorID;
	newAddress.AddressLine1 = address.AddressLine1;
	newAddress.AddressLine2 = address.AddressLine2;
	newAddress.AddressLine3 = address.AddressLine3;
	newAddress.City = address.City;
	newAddress.CountryID = address.CountryID;
	newAddress.State = address.State;
	newAddress.PostalCode = address.PostalCode;

	graph.Remittance_Address.Current = newAddress;
	graph.Remittance_Address.Update(newAddress);
}

if (contact.OverrideContact == true)
{
	graph.Remittance_Contact.Cache.Clear();
	APContact newContact = new APContact();
	// create new APContact
	newContact.OverrideContact = true;
	newContact = graph.Remittance_Contact.Update(newContact);
	if (newContact == null)
	{
		newContact = graph.Remittance_Contact.Current;
		graph.Remittance_Contact.Update(newContact);
	}

	newContact.VendorContactID = contact.VendorContactID;
	newContact.VendorID = contact.VendorID;
	newContact.Title = contact.Title;
	newContact.Salutation = contact.Salutation;
	newContact.Attention = contact.Attention;
	newContact.FullName = contact.FullName;
	newContact.Email = contact.Email;
	newContact.Phone1 = contact.Phone1;
	newContact.Phone1Type = contact.Phone1Type;
	newContact.Phone2 = contact.Phone2;
	newContact.Phone2Type = contact.Phone2Type;
	newContact.Phone3 = contact.Phone3;
	newContact.Phone3Type = contact.Phone3Type;
	newContact.Fax = contact.Fax;
	newContact.FaxType = contact.FaxType;

	graph.Remittance_Contact.Current = newContact;
	graph.Remittance_Contact.Update(newContact);
}

 

View original
Did this topic help you find an answer to your question?

5 replies

jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 701 replies
  • December 2, 2021

Hi @rjean09

 Can you please share the Acuamtica version?


Forum|alt.badge.img+1
  • Author
  • Semi-Pro III
  • 77 replies
  • December 2, 2021
jinin wrote:

Hi @rjean09

 Can you please share the Acuamtica version?

Build 20.211.0037


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 701 replies
  • December 2, 2021

Hi @rjean09 

Just changed the code for address part. Can you check once?
 

 if (graph.Remittance_Address.Current == null)
            {
                if (graph.Remittance_Address.Select().FirstOrDefault() != null)
                {
                    graph.Remittance_Address.Current.OverrideAddress = true;
                    graph.Remittance_Address.Cache.Update(graph.Remittance_Address.Current);                   
                }
            }
            else
            {
                graph.Remittance_Address.Current.OverrideAddress = true;
                if (graph.Remittance_Address.Select().FirstOrDefault() != null)
                {
                    graph.Remittance_Address.Current = graph.Remittance_Address.Select().FirstOrDefault();
                    graph.Remittance_Address.Update(graph.Remittance_Address.Current);
                }
            }


Forum|alt.badge.img+1
  • Author
  • Semi-Pro III
  • 77 replies
  • December 3, 2021

No luck.  With the code below I get a new APAddress record but it does not link to the new copy of APPayment so upon saving the RemitAddressID is still pointing to and updating the previous APAddress entry on the Quick Check being copied from.  There has to be a way to force the new record to get a copy of a new APAddress and get the new foreign key.  I’m sure I’m missing something simple but I can’t say I really understand the internals of how all of this works.

 


APAddress address = graph.Remittance_Address.Select();

if (address.OverrideAddress == true)
{
	payment.RemitAddressID = null;
	graph.Remittance_Address.Cache.Clear();
	APAddress newAddress = new APAddress();
	newAddress.OverrideAddress = true;
	newAddress = graph.Remittance_Address.Insert(newAddress);
	if (newAddress == null)
	{
		newAddress = graph.Remittance_Address.Current;
		graph.Remittance_Address.Update(newAddress);
	}

	newAddress.VendorAddressID = address.VendorAddressID;
	newAddress.VendorID = address.VendorID;
	newAddress.AddressLine1 = address.AddressLine1;
	newAddress.AddressLine2 = address.AddressLine2;
	newAddress.AddressLine3 = address.AddressLine3;
	newAddress.City = address.City;
	newAddress.CountryID = address.CountryID;
	newAddress.State = address.State;
	newAddress.PostalCode = address.PostalCode;


	graph.Remittance_Address.Current = newAddress;
	graph.Remittance_Address.Update(graph.Remittance_Address.Current);
	graph.Document.Update(payment);
}

Again, I want the new payment RemitAddressID to point to the newly created APAddress upon committing but it continues to be set to the old AddressID upon saving even when I clear this value. 

The new APAddress record is being created in the database but it is orphaned and still contains the values being set in code.  Changing any address values on the screen still continues to update the old APAddress.  

How can I:

  1. “Break” the link (foreign key) to the old APAddress
  2. Get the foreign key of the new payment to point to the new APAddress

Forum|alt.badge.img+1
  • Author
  • Semi-Pro III
  • 77 replies
  • Answer
  • December 3, 2021

Here is the solution I have now that works.  Sheer trial and error and lots of debugging:

// copy current address and contact
APAddress address = graphCurrent.Remittance_Address.Select();
APContact contact = graphCurrent.Remittance_Contact.Select();

graph.Document.Cache.SetDefaultExt<APQuickCheck.remitAddressID>(payment);
graph.Document.Cache.SetDefaultExt<APQuickCheck.remitContactID>(payment);

graph.Document.Insert(payment);

if (address.OverrideAddress == true)
{

	graph.Remittance_Address.Cache.Clear();
	APAddress newAddress = new APAddress();
	// create new APAddress
	newAddress.OverrideAddress = true;
	newAddress = graph.Remittance_Address.Update(newAddress);
	if (newAddress == null)
	{
		newAddress = graph.Remittance_Address.Current;
		graph.Remittance_Address.Update(newAddress);
	}

	newAddress.VendorAddressID = address.VendorAddressID;
	newAddress.VendorID = address.VendorID;
	newAddress.AddressLine1 = address.AddressLine1;
	newAddress.AddressLine2 = address.AddressLine2;
	newAddress.AddressLine3 = address.AddressLine3;
	newAddress.City = address.City;
	newAddress.CountryID = address.CountryID;
	newAddress.State = address.State;
	newAddress.PostalCode = address.PostalCode;

	graph.Remittance_Address.Current = newAddress;
	graph.Remittance_Address.Update(newAddress);
}

if (contact.OverrideContact == true)
{
	graph.Remittance_Contact.Cache.Clear();
	APContact newContact = new APContact();
	// create new APContact
	newContact.OverrideContact = true;
	newContact = graph.Remittance_Contact.Update(newContact);
	if (newContact == null)
	{
		newContact = graph.Remittance_Contact.Current;
		graph.Remittance_Contact.Update(newContact);
	}

	newContact.VendorContactID = contact.VendorContactID;
	newContact.VendorID = contact.VendorID;
	newContact.Title = contact.Title;
	newContact.Salutation = contact.Salutation;
	newContact.Attention = contact.Attention;
	newContact.FullName = contact.FullName;
	newContact.Email = contact.Email;
	newContact.Phone1 = contact.Phone1;
	newContact.Phone1Type = contact.Phone1Type;
	newContact.Phone2 = contact.Phone2;
	newContact.Phone2Type = contact.Phone2Type;
	newContact.Phone3 = contact.Phone3;
	newContact.Phone3Type = contact.Phone3Type;
	newContact.Fax = contact.Fax;
	newContact.FaxType = contact.FaxType;

	graph.Remittance_Contact.Current = newContact;
	graph.Remittance_Contact.Update(newContact);
}

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings