Use of functions in tables

imurphyimurphy Member Posts: 308
I want to add a column to a table to calculate a percentage. As a test I added a column and set this as the source expression:

Quantity/"Qty. to Invoice (Base)"

The problem is when "Qty. to Invoice (Base)" is 0.

I've been digging through David Studebaker's book among other sources and cannot find any references to what you can put in source expressions.

I'd guess I want something like

if ( iserror(Quantity/"Qty. to Invoice (Base)"),
0,
Quantity/"Qty. to Invoice (Base)")

Anyone know what you can put into source expressions?

I'm also going to have to format the output as a percentage but I can't find documentation on the available options for the format property on a numeric field. Again - any pointers?

Ian

Comments

  • krikikriki Member, Moderator Posts: 9,110
    Create a function in the table (and NOT the form!) that receives a records as parameter and returns a decimal
    Something like this:
    Function CalculatePercentage(recTheTable : record "The Table") OblnPercentage AS Decimal
    IF "Qty. to Invoice (Base)" = 0 THEN
      EXIT;
    EXIT(Quantity/"Qty. to Invoice (Base)" * 100);
    

    In the sourceexpression, you can use that function as
    CalculatePercentage(rec)
    

    Remark : you CANNOT filter on that field.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • imurphyimurphy Member Posts: 308
    I created a function in the form - why do you say to not do this?
  • krikikriki Member, Moderator Posts: 9,110
    imurphy wrote:
    I created a function in the form - why do you say to not do this?
    It is best to avoid as much as possible to put code in forms.
    One of the reasons is that if you put it in the table, you can more easily use that code in other objects.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.