Thursday, April 11, 2024

Computed column in View/DataEntity

private static server str compPurchQtyInvoiced()
{
	//return SysComputedColumn::sum(SysComputedColumn::returnField(
	//        tableStr(InboundOrderLinesOverview),
	//        identifierStr(InventTransPurchLine),
	//    fieldStr(InventTrans, Qty)));

	SysDictTable InventTrans = new SysDictTable(tableNum(InventTrans));
	SysDictTable InventTransOriginPurchLineLoc = new SysDictTable(tableNum(InventTransOriginPurchLine));
	str          val;

	str     inventtransid = SysComputedColumn::returnField(dataentityviewstr(InboundOrderLinesOverview), identifierstr(PurchLine), fieldstr(PurchLine, InventTransId));

	//select SUM(QTY) from inventtrans
	//    join InventTransOriginPurchLine on InventTransOriginPurchLine.INVENTTRANSORIGIN = inventtrans.INVENTTRANSORIGIN
	//    where InventTransOriginPurchLine.PURCHLINEINVENTTRANSID = 'L00834739'
	//    AND inventtrans.STATUSRECEIPT in (1,2)


	val = strFmt("select SUM(%1) from %2 join %3 on %3.%4 = %2.%5 where %3.%6 = %7 AND %2.%8 = %9",
		InventTrans.fieldName(fieldNum(InventTrans, Qty), DbBackend::Sql),
		InventTrans.name(DbBackend::Sql),
		InventTransOriginPurchLineLoc.name(DbBackend::Sql),
		InventTransOriginPurchLineLoc.fieldName(fieldNum(InventTransOriginPurchLine, INVENTTRANSORIGIN), DbBackend::Sql),
		InventTrans.fieldName(fieldNum(InventTrans, INVENTTRANSORIGIN), DbBackend::Sql),
		InventTransOriginPurchLineLoc.fieldName(fieldNum(InventTransOriginPurchLine, PURCHLINEINVENTTRANSID), DbBackend::Sql),
		inventtransid,
		InventTrans.fieldName(fieldNum(InventTrans, StatusReceipt), DbBackend::Sql),
		SysComputedColumn::returnLiteral(1));

	return val;
}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8