I have a custom processing screen that sets some custom fields (for stale dated checks, they get a lot of these due to small amount refunds that never get cashed). My client wants these to be voided automatically at the same time which means in code it needs to call the void action on the APPaymentEntry graph, remove the hold flag and call the release action. Not having much luck pulling all of this together. We had an import scenario to do the void after setting the stale dated info but they want it to be all in one step.
Here is the main processing loop. Most of these will be Quick Checks (but not all)
Correction, these will only be quick checks
public static void Process(List<APPayment> payments)
{
var globalError = false;
var graph = CreateInstance<APPaymentEntry>();
var checkNumber = string.Empty;
DateTime? currBusinessDate = graph.Accessinfo.BusinessDate;
Guid currUser = graph.Accessinfo.UserID;
foreach (var payment in payments) {
var lineError = false;
try
{
graph.Clear();
checkNumber = payment.ExtRefNbr;
graph.Document.Current = payment;
var origCheckNo = graph.Document.GetValueExt<APRegisterExt.usrOrigCheckNo>(payment);
if (origCheckNo == null || (string)origCheckNo == string.Empty)
{
PXDatabase.Update<APRegister>(new PXDataFieldAssign<APRegisterExt.usrStaleDated>(true),
new PXDataFieldAssign<APRegisterExt.usrStaleDatedBy>(currUser),
new PXDataFieldAssign<APRegisterExt.usrStaleDatedOn>(currBusinessDate),
new PXDataFieldAssign<APRegisterExt.usrOrigCheckNo>(payment.ExtRefNbr),
new PXDataFieldRestrict<APRegister.refNbr>(payment.RefNbr),
new PXDataFieldRestrict<APRegister.docType>(payment.DocType));
}
else
{
PXDatabase.Update<APRegister>(new PXDataFieldAssign<APRegisterExt.usrStaleDated>(true),
new PXDataFieldAssign<APRegisterExt.usrStaleDatedBy>(currUser),
new PXDataFieldAssign<APRegisterExt.usrStaleDatedOn>(currBusinessDate),
new PXDataFieldRestrict<APRegister.refNbr>(payment.RefNbr),
new PXDataFieldRestrict<APRegister.docType>(payment.DocType));
}
// Go ahead and void it here?
// this doesn't seem to do anything (not voided, put on hold, etc.)
var result = graph.VoidCheck(new PXAdapter(graph.Document));
graph.Persist();
// Once the above works, we need to take off hold
// Then release
}
catch (Exception e)
{
//set line error to true so will skip the process correct below
lineError = true;
//set globaError flag to true to get the global message
globalError = true;
//create a custom error message to post on the grid
var message = "Error Processing Check: " + checkNumber + ": " + e.Message;
PXTrace.WriteError(message);
PXTrace.WriteError(e);
//add the custom error message to the grid line
PXProcessing.SetError(payments.IndexOf(payment), message);
}
var messageTwo = "Check: " + checkNumber + " Was Processed.";
if (!lineError) PXProcessing.SetInfo(payments.IndexOf(payment), messageTwo);
}