Computed columns in Views D365FO x++


Here is the computed column example in view which return Yes/No based on if condition

/// <summary>
/// </summary>
/// return Yes if External Customer has attachment else No
/// </summary>
public static server str computeFileAttached()
{
str customerRecID;
str fileAttached;
str result;

SysDictTable dictDocuRef = new SysDictTable(tableNum(DocuRef));

customerRecID=SysComputedColumn::returnField(tableStr(TestExtCustomerView), identifierStr(TestExtCustomerTable), fieldStr(TestExtCustomerTable, RecId));

str s = strFmt('SELECT TOP 1 %1 FROM %2 WHERE %2.%3 = %4 
AND %2.%5 = %6',
dictDocuRef.fieldName(fieldNum(DocuRef, RefRecId), DbBackend::Sql),
dictDocuRef.name(DbBackend::Sql),
dictDocuRef.fieldName(fieldNum(DocuRef, RefRecId), DbBackend::Sql),customerRecID,
dictDocuRef.fieldName(fieldNum(DocuRef,RefTableId),DbBackend::Sql),"9708");

result = strFmt('ISNULL((%1), \'\')', s);

return SysComputedColumn::if(
SysComputedColumn::returnLiteral("No"),
SysComputedColumn::returnLiteral("Yes"));
SysComputedColumn::equalExpression(result,'0'),

}

Hope this helps.

Have a nice day.Stay Safe.

Comments

Popular posts from this blog

x++ code to add hyperlink to a field in D365FO

x++ code to get Vendor Email Address based on Purpose in Dynamics 365 for Operations

x++ code to get Customer Address based on purpose in ax 2012