添加DAC及其图表的新扩展时出现的问题

时间:2017-10-25 06:24:51

标签: acumatica

我正在尝试将Contract DAC及其新扩展添加到我的APInvoiceEntry Graph的扩展中,以便进行一些验证,我真的做错了,但我不知道究竟是什么搞砸了可能是Contracts DAC的初始化以及评估逻辑?它试图将一些Contracts逻辑强制转换为APTran并发送“无法投射”错误。

最终目标是查看“帐单和付款”中每行中选定的项目和分支,并根据项目ID和ContractExt DAC扩展中创建的新BranchID字段进行评估。

我得到的当前错误的跟踪是:

Unable to cast object of type 'PX.Objects.AP.APTran' to type 'PX.Objects.CT.Contract'. 

at PX.Objects.AP.APInvoiceEntry_Extension.APTran_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e, PXRowUpdating InvokeBaseHandler) 
at PX.Data.PXCache.OnRowUpdating(Object item, Object newitem, Boolean externalCall) 
at PX.Data.PXCache`1.Update(IDictionary keys, IDictionary values) 
at PX.Data.PXGraph.ExecuteUpdate(String viewName, IDictionary keys, IDictionary values, Object[] parameters) 

这让我相信我可能不会正确地带来合同DAC。

代码如下:

图表:

namespace PX.Objects.AP
{
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
    public PXSelect<Contract, Where<Contract.contractID, Equal<Current<APTran.projectID>>>> Contract;
    protected void APTran_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e, PXRowUpdating InvokeBaseHandler)
    {
        Contract conRow = (Contract)e.NewRow as Contract;
        ContractExt conRowE = PXCache<Contract>.GetExtension<ContractExt>(conRow);
        APTran row = e.NewRow as APTran;
        int? projectid = conRow.ContractID;
        int? baseprojectid = row.ProjectID;
        int? basebranchid = row.BranchID;
        int? branchid = conRowE.UsrBranch;
        if (
            //Check to make sure that selected Branch and Project match
            baseprojectid == projectid &&
            basebranchid != branchid
            )
        {
            throw new PXSetPropertyException("Branch and  project must match", PXErrorLevel.RowError);
        }
    }
}
}

DAC:

namespace PX.Objects.CT
{
public class ContractExt : PXCacheExtension<PX.Objects.CT.Contract>
{
    [Branch]
    public virtual int? UsrBranch { get; set; }
    public abstract class usrBranch : IBqlField { }
}}

这一切都正确编译。错误会像您期望的那样弹出,如下所示: APTran Unable to Cast Error

1 个答案:

答案 0 :(得分:1)

使用APTran时,您尝试将Contract行转换为(Contract)e.NewRow,这就是您遇到错误的原因。如下所示进行选择可以为您提供所需的信息。

public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
    protected void APTran_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e, PXRowUpdating InvokeBaseHandler)
    {
        Contract conRow = PXSelect<Contract, Where<Contract.contractID, Equal<Current<APTran.projectID>>>>.Select(Base);
        ContractExt conRowE = conRow.GetExtension<ContractExt>();
        APTran row = e.NewRow as APTran;
        int? projectid = conRow.ContractID;
        int? baseprojectid = row.ProjectID;
        int? basebranchid = row.BranchID;
        int? branchid = conRowE.UsrBranch;
        if (
            //Check to make sure that selected Branch and Project match
            baseprojectid == projectid &&
            basebranchid != branchid
            )
        {
            throw new PXSetPropertyException("Branch and  project must match", PXErrorLevel.RowError);
        }
    }
}

您可以使用PXSelect简单地选择基本DAC,然后获取扩展值,如上例所示(您已经在另一个调用中使用了 - 这可以正常工作)。如果你想显示DAC扩展并且图形还没有基本DAC的视图,你可以添加一个视图,否则我只需要在需要时使用PXSelect。