Good day,
I need to pass values from a custom field in APTran in Bills and Adjustment at the moment when the Bill is released and the Journal Transaction is created, I need to pass the values to GLTran to a custom field, but when I use the Actions.PressSave I get a null error, Object reference not set to an instance of an object. I can't find which is the value I am missing or which another field appears as null and is required, I compared between the null fields on cache and the fields in the database that say that are required, but all the fields that appear as null are allowed to be null so I can't find the problem.
I would appreciate some assistance please.
public class APInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AP.APInvoiceEntry>
{
#region Event Handlers
public delegate IEnumerable ReleaseDelegate(PXAdapter adapter);
PXOverride]
public virtual IEnumerable Release(PXAdapter adapter, ReleaseDelegate baseMethod)
{
var adapters = adapter.Get();
APInvoice api = Base.Document.Current;
APInvoice finance = Base.CurrentDocument.Current;
if (finance != null)
{
baseMethod(adapter);
if (finance.BatchNbr != null)
{
var journalgraph = PXGraph.CreateInstance<JournalEntry>();
int? acct = finance.APAccountID;
// Iterate through each APTran line
foreach (APTran apTran in PXSelect<APTran, Where<APTran.tranType, Equal<Required<APTran.tranType>>, And<APTran.refNbr, Equal<Required<APTran.refNbr>>>>>.Select(Base, api.DocType, api.RefNbr))
{
APTranExt apTranExt = PXCache<APTran>.GetExtension<APTranExt>(apTran);
GLTran journaltran = SelectFrom<GLTran>.Where<GLTran.refNbr.IsEqual<@P.AsString>.And
<GLTran.tranType.IsEqual<@P.AsString>.And
<GLTran.module.IsEqual<@P.AsString>.And
<GLTran.tranLineNbr.IsEqual<@P.AsInt>>>>>.View.SelectSingleBound(journalgraph, null, apTran.RefNbr, apTran.TranType, "AP", apTran.LineNbr);
if (journaltran != null)
{
GLTranExt glTranExt = PXCache<GLTran>.GetExtension<GLTranExt>(journaltran);
//string journaldesc = apTranExt.UsrOptionalDesc;
//journalgraph.GLTranModuleBatNbr.Cache.SetValue<GLTranExt.usrOptDescription>(journaltran, journaldesc);
glTranExt.UsrOptDescription = apTranExt.UsrOptionalDesc;
journalgraph.GLTranModuleBatNbr.Cache.Update(journaltran);
}
}
// Save the changes
journalgraph.Actions.PressSave(); //Error
}
}
return adapters;
} #endregion
}