I'm trying to add a virtual field in a view by setting the IsVirtual property to yes, but I have got the following error.
This is the property I have given to the virtual field.
so I have tried adding the computed field in the view and have added a method, but this method is not getting hit. And I have tried calling this method in the postLoad() method and while debugging I have found that the SysComputedColumn is not returning the value.
This is the property screen for the computed field.
This is the method I have written.
public static server str RNIQuantity()
qty RNIQuantity, vendPackingSlipQty;
vendPackingSlipTransRecId = str2Int64(SysComputedColumn::returnField(tableStr(MUEVendAccruedPOLedgerDateView), identifierStr(VendPackingSlipTrans), fieldStr(VendPackingSlipTrans, RecId)));
vendPackingSlipQty = any2Real(SysComputedColumn::returnField(tableStr(MUEVendAccruedPOLedgerDateView), identifierStr(VendPackingSlipTrans), fieldStr(VendPackingSlipTrans, Qty)));
select sum(ReceiveNow) from vendInvoiceInfoTableExpandedView
where vendInvoiceInfoTableExpandedView.JournalRefRecId == vendPackingSlipTransRecId &&
vendInvoiceInfoTableExpandedView.JournalRefTableId == tableNum(VendPackingSlipTrans)
&& vendInvoiceInfoTableExpandedView.ParmJobStatus == ParmJobStatus::Executed
&& vendInvoiceInfoTableExpandedView.TransDate <= today();
if (vendInvoiceInfoTableExpandedView.ReceiveNow < vendPackingSlipQty)
RNIQuantity = (vendPackingSlipQty - vendInvoiceInfoTableExpandedView.ReceiveNow);
So my questions are,
Why it throws an error when adding the Virtual field?Why the method I have created for the computed field is not getting hit?Why the SysComputedColumn is not returning the value?What am I missing here? Experts out there please provide me with suggestions
You should decide whether you want to build a virtual field or a computed column and implement the one thing. Your method do partially what you would do for a computed column and partial what you would do for a virtual field, and ultimately it makes no sense whatsoever.
If you want to build a virtual field, call your select statement to obtain sum(ReceiveNow) and assign it to this.RNIQty. Forget all calls to SysComputedColumn class - this would be used for computed columns, not for virtual fields.
If you want to create a computed column, your method must return T-SQL code for obtaining the value from database. Your attempts to obtain the value in X++ won't work.
You ended up with code where you're trying, for example, take the name of Qty field (not its value), convert it to a number (always zero) and compare it with vendInvoiceInfoTableExpandedView.ReceiveNow. That's clearly not very useful.
Thanks for your reply Martin, yes, at first I have tried to use a virtual field but I have received an error saying.
could you please let me know why I'm getting this error even after setting the IsVirtual property to Yes? If I can figure out why this error occurs I can achieve what you said here
Martin Dráb said:If you want to build a virtual field, call your select statement to obtain sum(ReceiveNow) and assign it to this.RNIQty.
Any suggestions ? Martin Dráb
I don't know, either it's a bug or virtual fields are supported only on data entities and not views (and the bug is exposing the property in views). You can log a support request to learn which case it is.
Consider using a display method instead.
Thanks for your reply Martin.