The following onOpen event handler adds a calculated field to a query.

function invoice1_onOpen( )

c = new Field( ) 

c.fieldName := "Total" 

this.rowset.fields.add( c ) 

c.beforeGetValue := {||this.parent["Qty"].value * this.parent["PricePer"].value} 

Note that the this in the second statement refers to the query, but in the codeblock, this refers to the calculated field.