Hi everybody,
I have a method in a view and I use it in a field of the view. My problem is that I need to debug the method to find why it’s not working. This is my code:
public static server str costvalue()
{
#define.ViewName(TRV_VentasPorRenglon)
#define.DataSourceName(“CustInvoiceTrans_1”)
#define.FieldRecId(“RecId”)
str sAccountNum;
real number;
DictView dictView2;
CustInvoiceTrans custInvoiceTrans;
// Construct a DictView object for the present view.
dictView2 = new DictView(tableNum(#ViewName));
// Get a string that has the target field name propertly qualified with an alias (such as “A.” or “B.”).
sAccountNum = dictView2.computedColumnString(#DataSourceName,#FieldRecId, FieldNameGenerationMode::FieldList, true);
number = CustInvoiceTrans::findRecId(str2int64(sAccountNum)).costValue();
return sAccountNum;
}
Right now I’m returning the RecId of the CustInvoiceTrans, but I need to return the value “number”. This variable contains the value from the method costValue of the CustInvoiceTrans. Can anybody help me?
Thanks in advance
Update:
I changed the return format to real, because my field is real. Now I have anther problem, I try to use the value that is in the variable sAccount, convert it to int64, and then use it in the method find of the CustInvoiceTrans, but I still get nothing.
But, when I put a RecId (one real value, hardcode), it works! I need to get the value that is in sAccount to use it in the find method.
The method should return the definition of your computed column as T-SQL code. Such code would be added to the view definition stored in SQL Server database.
Do you think that custInvoiceTrans.costValue() returns such T-SQL code? Of course not; it returns a number, which isn’t what you want. Actually, you’ve created a computed column that will always return zero. You can verify it by looking at the view definition in database (which is a technique you should always use if your view doesn’t work as expected).
First of all, accept the fact that computed columns returns T-SQL code calculating the value; they don’t return the value directly. Then you’ll see that your code doesn’t make sense and you have to start again from scratch.
As the first step, define the required T-SQL code. Only then start using functions like computedColumnString() to generate such code.
Obviously, the method must always return a string, because T-SQL code is written as text.
Hi Martin,
Thanks for your reply. Last week I have almost the same answer, but I really need that value. Can you please put an example of what I can do to get that value?
Thanks in advance,
You would have to rewrite CustInvoiceTrans.costValue() to T-SQL, which looks like a lot of work. I’m sorry, but I don’t have time to do it for you, unless you hire me to do that.
If I was you, I would challenge the whole idea of using a computed column. It’s clear that the decision was done without understanding what it actually means. Maybe you can use the display method directly, or you can calculate the cost value in X++ (by calling CustInvoiceTrans.costValue() as usual) and storing it a separate table.
Thanks Martin,
I thought there were some examples in Internet, and I don’t want you to work for free. We think that it would be easier to do a computed column. Anyway, thanks for your response Martin, we will be looking fot another solution, if we found one I will share it.
Thank you
Please don’t forget that I already suggested two other solutions.