TOPIC: Accessing Other Fields
Accessing Other Fields 3 Years, 9 Months ago
I'm new to Suneido, and am trying to understand the language. The manual is good for showing syntax, but sometimes it doesn't fill in the blanks for me. I created a table, and would like to have a couple of the fields derive their value from other fields in the database. I realize this is probably a really stupid question for most of you, but I can't seem to find any examples of how to do this.

Any help would be appreciated. Thanks!
Re:Accessing Other Fields 3 Years, 9 Months ago
this is just part of realy good manual searched for terms "derived columns". I hope that it will help you. You can see also a lot of examples in "Accounting application"

Derived Columns
When a column named is created with a capitalized name, it is a derived (calculated) column. It is not physically stored in the database. These columns can be used for searching and sorting, but they cannot be used as index or key columns.

A function called "Rule_" $ fieldname must exist to calculate the column value. It is called as if it were a method of the record so it may access the other columns of the record as dot variables.

For example:

create mytable (item quantity rate Total) key (item)

{ return .quantity * .rate; }

The total column of mytable will now be automatically calculated by multiplying the quantity column times the rate column. The total column can be used like other columns:

mytable where total > 100 sort total
Re:Accessing Other Fields 3 Years, 9 Months ago
Sorry, I guess I was a bit vague. I'm looking for a way to take a few different fields from the table and put them into an equation to derive a value for a 4th field. For instance, let's say I have the following fields:


I want to have target_heart be a readonly field whose value is automatically calculated based on the values entered into the other fields using the following equation:

220 - age - resting_heart * percent_workout + resting_heart

Does this make more sense? I saw the manual text you are referring to, but it doesn't seem to address this type of thing.
Re:Accessing Other Fields 3 Years, 9 Months ago
Hi again,

if I understand you ...

update table definition (by typing in query window, first letter must be Uppercase - mark for computed field)

ensure your_table_name (Target_heart)

create new item in library

function ()
return (220 - .age - .resting_heart * .percent_workout + .resting_heart)

after this you can access this field eg. in form jsut with query "your_table_name"

if you would like to use "computed" field just once, you can type

your_table_name extend target_heart = (220 - age - resting_heart * percent_workout + resting_heart)
Re:Accessing Other Fields 3 Years, 8 Months ago
Thank you for your help. I'm still having difficulties, but I think it's due to my lack of understanding of how the language works (not the info you gave).

Thanks, I'll keep plugging away!