X++ 缺少 SysComputedColumn::Sum 文档,或者如何求和?

huangapple go评论50阅读模式
英文:

X++ Missing SysComputedColumn::Sum documentation, or how to sum?

问题

我正在尝试通过Sys计算列来对视图中的一些值进行求和。我正在使用SysComputedColumn,因为我在视图的数据源中提到了这些值,而不是直接在视图中。我可以进行乘法和除法运算,但是当我需要进行求和时,就出现了问题。

如何使用SysComputedColumn::Sum()方法?我找不到任何文档。它只允许一个参数,我不知道该如何处理。我理解这个方法对吗,还是应该使用其他方法?

FYI:对于来自inventTable的非常特定的数据部分,它是TaraWeight + NetWeight = grossWeight,但我无论如何都无法处理SysComputedColumn中的'+'运算符...我至少还需要一次使用'itemWeight' + 'packingingWeight' + 'palletWeight',所以解释一下'sum'将会很有帮助!

请帮助 X++ 缺少 SysComputedColumn::Sum 文档,或者如何求和?

我尝试使用SysComputedColumn::Sum(),将两个值放在单个参数中,并使用'+'运算符 - 没有好的结果。我尝试通过将数据类型更改为'real',然后将它们汇总并返回为'str',因为计算列使用'str'(我只是这么认为,我刚刚开始学习X++) - 我认为在编译代码后甚至都无法编译。在MSN上,我尝试查找任何示例、文档或其他方法,但没有找到任何信息。

英文:

I am trying to sum some values in view via Sys computed columns. I am using SysComputedColumn as I have mentioned values in view's datasources, not directly in view. I am multiplying and diving all fine, but then i need sum and there goes my problem.

How to use SysComputedColumn::Sum() method? I can't find any docs at all. It's allowing just one argument which I dont get how to deal with. Did I get this method right, or should I use some different method?

FYI: It's TaraWeight + NetWeight = grossWeight for very specific part of data from inventTable, but I cant deal with '+' in SysComputedColumn anyhow.. I will need it one more time at least with 'itemWeight' + 'packingingWeight' + 'palletWeight', so explaining 'sum' would be great!

Please help X++ 缺少 SysComputedColumn::Sum 文档,或者如何求和?

I tried to use SysComputedColumn::Sum() with both values in single argument with '+' operator - no good result. I tried to put values together via changing datatypes to 'real', then summarize them and return back as 'str' as computed columns works with str (I just think so, I just started X++) - think cant event compile code after.
At MSN, I tried to find any example, docu or other method, but did not find any..

答案1

得分: 1

你必须知道并使用交叉引用。
它会为你提供大量示例。

我只会给你一个示例:

/// <returns>包含度量定义的字符串。</returns>
/// <remarks>返回的值类似于:'ABS(SUM(COSTAMOUNTPOSTED) + SUM(COSTAMOUNTADJUSTMENT))'/// </remarks>
public static str cogs()
{
    TableName   viewName  = tableStr(InventTransGrouped);
    str         sumPosted = SysComputedColumn::sum(
                                SysComputedColumn::returnField(viewName,
                                                                identifierStr(InventTrans),
                                                                fieldStr(InventTrans, CostAmountPosted)));
    str         sumAdjusted = SysComputedColumn::sum(
                                SysComputedColumn::returnField(viewName,
                                                                identifierStr(InventTrans),
                                                                fieldStr(InventTrans, CostAmountAdjustment)));
    return SysComputedColumn::negative(SysComputedColumn::add(sumPosted, sumAdjusted));
}

在你的情况下,你不应该使用 sum,而应该使用 SysComputedColumn::add 与这两个字段一起使用。

可以使用硬编码名称,但你将无法获得编译检查和交叉引用的好处:

return 'TaraWeight + NetWeight';

更好的方式:

return fieldStr(InventTable, TaraWeight) + '+' + fieldStr(InventTable, NetWeight);

有一些文档,但它不是很好。

英文:

You have to know and use the cross reference.
It will give you plenty of examples.

I will give you only one:

/// &lt;summary&gt;Defines the COGS derived column.&lt;/summary&gt;
/// &lt;returns&gt;A string with the measure definition.&lt;/returns&gt;
/// &lt;remarks&gt;The returned value is similar to: &#39;ABS(SUM(COSTAMOUNTPOSTED) + SUM(COSTAMOUNTADJUSTMENT))&#39;/// &lt;/remarks&gt;
public static str cogs()
{
    TableName   viewName  = tableStr(InventTransGrouped);
    str         sumPosted = SysComputedColumn::sum(
                                SysComputedColumn::returnField(viewName,
                                                                identifierStr(InventTrans),
                                                                fieldStr(InventTrans, CostAmountPosted)));
    str         sumAdjusted = SysComputedColumn::sum(
                                SysComputedColumn::returnField(viewName,
                                                                identifierStr(InventTrans),
                                                                fieldStr(InventTrans, CostAmountAdjustment)));
    return SysComputedColumn::negative(SysComputedColumn::add(sumPosted, sumAdjusted));
}

In your case you should not use sum, instead use SysComputedColumn::add with the two fields.

You could use hard code names also, but you will not get the benefit of compile check and cross reference:

return &#39;TaraWeight + NetWeight&#39;;

Better:

return fieldStr(InventTable,TaraWeight) + &#39;+&#39; + fieldStr(InventTable,NetWeight);

There is some documentation but it is not good.

huangapple
  • 本文由 发表于 2023年6月19日 14:38:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76504165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定