Skip to main content

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
}

 

Can you attach call stack, please?


@orlandonegron43 

 

Have you tried including a

if(Base == null)

{ return adapter.Get()}


Hi @orlandonegron43 in your case I would suggest to override ReleaseDocProc method of APReleaseProcess graph.

Sample code:
 

public class APReleaseProcessExt : PXGraphExtension<APReleaseProcess>
{
public delegate List<APRegister> ReleaseDocProcDelegate(JournalEntry je, APRegister doc, bool isPrebooking, out List<INRegister> inDocs);

PXOverride]
public virtual List<APRegister> ReleaseDocProc(JournalEntry je, APRegister doc, bool isPrebooking, out List<INRegister> inDocs, ReleaseDocProcDelegate baseMethod)
{
var result = baseMethod(je, doc, isPrebooking, out List<INRegister> inDocsLocal);
foreach (APTran aptran in Base.APTran_TranType_RefNbr.Select(doc.DocType, doc.RefNbr))
{
GLTran gltran = je.GLTranModuleBatNbr.Select().FirstTableItems.Where(t => t.TranLineNbr == aptran.LineNbr).FirstOrDefault();
if (gltran != null)
{
gltran.TranDesc = "Test";
je.GLTranModuleBatNbr.Update(gltran);
}
}
je.Persist();
inDocs = inDocsLocal;
return result;
}
}

 


Hi @orlandonegron43 in your case I would suggest to override ReleaseDocProc method of APReleaseProcess graph.

Sample code:
 

public class APReleaseProcessExt : PXGraphExtension<APReleaseProcess>
{
public delegate List<APRegister> ReleaseDocProcDelegate(JournalEntry je, APRegister doc, bool isPrebooking, out List<INRegister> inDocs);

>PXOverride]
public virtual List<APRegister> ReleaseDocProc(JournalEntry je, APRegister doc, bool isPrebooking, out List<INRegister> inDocs, ReleaseDocProcDelegate baseMethod)
{
var result = baseMethod(je, doc, isPrebooking, out List<INRegister> inDocsLocal);
foreach (APTran aptran in Base.APTran_TranType_RefNbr.Select(doc.DocType, doc.RefNbr))
{
GLTran gltran = je.GLTranModuleBatNbr.Select().FirstTableItems.Where(t => t.TranLineNbr == aptran.LineNbr).FirstOrDefault();
if (gltran != null)
{
gltran.TranDesc = "Test";
je.GLTranModuleBatNbr.Update(gltran);
}
}
je.Persist();
inDocs = inDocsLocal;
return result;
}
}

 

Amazing! it worked! I totally forgot to consider the screen of releasing ap documents and that's why I could not find the method that creates the journal entries when the bill is released, thank you so much!


@orlandonegron43 there are actually special methods for that. 

APReleaseProcess class:

		/// <summary>
/// The method to insert invoice details GL transactions
/// for the <see cref="APTran"/> entity inside the
/// <see cref="ReleaseInvoice(JournalEntry, ref APRegister, PXResult{APInvoice, CurrencyInfo, Terms, Vendor}, bool, out List{INRegister})"/> method.
/// <see cref="GLTranInsertionContext"/> class content:
/// <see cref="GLTranInsertionContext.APRegisterRecord"/>,
/// <see cref="GLTranInsertionContext.APTranRecord"/>.
/// </summary>
public virtual GLTran InsertInvoiceDetailsTransaction(
JournalEntry je,
GLTran tran,
GLTranInsertionContext context)
{
return je.GLTranModuleBatNbr.Insert(tran);
}

/// <summary>
/// The method to insert invoice details schedule GL transactions
/// for the <see cref="APTran"/> entity inside the
/// <see cref="ReleaseInvoice(JournalEntry, ref APRegister, PXResult{APInvoice, CurrencyInfo, Terms, Vendor}, bool, out List{INRegister})"/> method.
/// <see cref="GLTranInsertionContext"/> class content:
/// <see cref="GLTranInsertionContext.APRegisterRecord"/>,
/// <see cref="GLTranInsertionContext.APTranRecord"/>.
/// </summary>
public virtual GLTran InsertInvoiceDetailsScheduleTransaction(
JournalEntry je,
GLTran tran,
GLTranInsertionContext context)
{
return je.GLTranModuleBatNbr.Insert(tran);
}

/// <summary>
/// The method to insert invoice details POReceiptLine GL transactions
/// for the <see cref="POReceiptLine"/> entity inside the
/// <see cref="ReleaseInvoice(JournalEntry, ref APRegister, PXResult{APInvoice, CurrencyInfo, Terms, Vendor}, bool, out List{INRegister})"/> method.
/// <see cref="GLTranInsertionContext"/> class content:
/// <see cref="GLTranInsertionContext.APRegisterRecord"/>,
/// <see cref="GLTranInsertionContext.APTranRecord"/>,
/// <see cref="GLTranInsertionContext.POReceiptLineRecord"/>.
/// </summary>
public virtual GLTran InsertInvoiceDetailsPOReceiptLineTransaction(
JournalEntry je,
GLTran tran,
GLTranInsertionContext context)
{
return je.GLTranModuleBatNbr.Insert(tran);
}

You just need to override those and populate the value of the custom field before inserting of the GL Tran.

 

 


Reply