D365 FO 视图Computed字段

从AX2012开始,AX的View增加了Computed类型的字段,具体的操作步骤,参见下文。
https://docs.microsoft.com/en-us/dynamicsax-2012/developer/walkthrough-add-a-computed-column-to-a-view#add-a-static-method-to-the-view
Computed列的原理是通过SQL函数或运算符,对其他实体字段进行组合加工得到一个新的列。
比如表里有日期字段和时间字段,但是没有日期时间字段,需要在视图里增加日期时间字段,可以通过Computed字段来组合,视图里创建一个新的方法

实体表如下所示,只有日期和时间字段。

在View里增加一个运行在服务器端的静态私有方法

private server static str transDateTime()
    {
        return SysComputedColumn::getDateAdd(
                SysComputedColumn::returnField(tableStr(DateTimeTest), "DateTimeTest",  fieldStr(DateTimeTest, Time)) + " - "
                            + int2str(DateTimeUtil::getTimeZoneOffset(DateTimeUtil::utcNow(), DateTimeUtil::getUserPreferredTimeZone())) + "* 60",
                SysComputedColumn::returnField(tableStr(DateTimeTest), "DateTimeTest",  fieldStr(DateTimeTest, TransDate)),
                SysComputedColumnDatePart::Second);
    }

把新增的方法映射到View的字段上。

 显示效果如上图所示。

原文地址:https://www.cnblogs.com/Farseer1215/p/12953083.html