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 :)
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..
You have to know and use the cross reference. It will give you plenty of examples.
I will give you only one:
/// <summary>Defines the COGS derived column.</summary>
/// <returns>A string with the measure definition.</returns>
/// <remarks>The returned value is similar to: '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));
}
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 'TaraWeight + NetWeight';
Better:
return fieldStr(InventTable,TaraWeight) + '+' + fieldStr(InventTable,NetWeight);
There is some documentation but it is not good.