0
votes

Customized decimal type field generates error after being published.

I've tried many different syntaxes, if isnull(), etc and for some reason I am not thinking to try the right one.

if (tran != null && tran.TranLineNbr != null &&
    arTran != null && arTran.TranType == tran.TranType &&
    arTran.RefNbr == tran.RefNbr && arTran.LineNbr == tran.TranLineNbr)
{    
    decimal? amtOrg = arTran.GetExtension<ARTranExt>().UsrDLYAMTORG;
    tran.GetExtension<GLTranExt>().UsrDLYAMTORG = amtOrg;
}

The value on release should go from Ar to Gl. All the other custom fields work, but not the decimal.

"Error: An error occurred during processing of the field Original Amount. Specified cast is not valid."

1
All most of the time is an issue with the way you defined fields inside DAC extension. Check the type of UsrDLYAMTORG, in the same time the PXDBType of usrDLYAMTORG class - Cosmin Antohe

1 Answers

0
votes

Your data access class should look similar to

/// <summary>
/// Adds extension fields to and modifies attributes in <see cref="ARTran"/>.
/// </summary>
public sealed class ARTranExt : PXCacheExtension<ARTran>
{
    public abstract class usrDLYAMTORG : IBqlField
    {
    }
    [PXDBDecimal]
    [PXUIField(DisplayName = "Your Field Name")]
    [PXDefault(TypeCode.Decimal, "0.00", PersistingCheck = PXPersistingCheck.Nothing)]
    public decimal? UsrDLYAMTORG { get; set; }
}

In regards to bringing a custom value from AR to GL on release we have accomplished the same with the following code.

public class ARReleaseProcessExtension : PXGraphExtension<ARReleaseProcess>
{
    public delegate GLTran InsertInvoiceDetailsTransactionDel(JournalEntry je, GLTran tran, ARReleaseProcess.GLTranInsertionContext context);

    [PXOverride]
    public virtual GLTran InsertInvoiceDetailsTransaction(JournalEntry je, GLTran tran, ARReleaseProcess.GLTranInsertionContext context, InsertInvoiceDetailsTransactionDel del)
    {
        tran.GetExtension<GLTranExt>().UsrDLYAMTORG = context.ARTranRecord.GetExtension<ARTranExt>().UsrDLYAMTORG;

        return del?.Invoke(je, tran, context);
    }
}