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