I gather this can be done but am having trouble getting it to work! If I simply add globals.myMethod() to a calculation should it trigger the method? If so, can I get a value from the method back into the calculation? i.e. can I run the method, set a global variable with a result and then use that variable in the next steps of the calculation?
I would really like to be able to run an sql select as part of a global method (triggered from a calculation) in order to return a value to a dataprovider without having to resort to relationships.
Any help gratefully received!
drookwood:
I gather this can be done but am having trouble getting it to work! If I simply add globals.myMethod() to a calculation should it trigger the method? If so, can I get a value from the method back into the calculation? i.e. can I run the method, set a global variable with a result and then use that variable in the next steps of the calculation?
I would really like to be able to run an sql select as part of a global method (triggered from a calculation) in order to return a value to a dataprovider without having to resort to relationships.
Any help gratefully received!
I use this as follows:
In a global called Duration, I have:
return globals.Days_Between(due_diligence_,date_entered);
My method (Days_Between) then looks like (simplified..):
var date1= arguments[0], date2=arguments[1]; {
if (!date1) { return -999};
{code here}
return Math.round(difference_ms/ONE_DAY)
Both the calculation and the method need to return a value for every outcome, but other than that, you can do almost anything (I would be
careful about changing other values in the record, but that is a guess, the guys from Servoy may be able to tell you for certain)
that should work fine.
You shouldn’t do time consuming stuff like a sql query in a calculation. A calculation should be as quick as possible.
dbonnet: thanks - it was the use of ‘return’ in the method that I wasn’t getting. Now works OK.
jcompagner: what if the sql is simply to get a single value? for example: I need to get a value into a dataprovider from a related record. Is it always better to establish a relationship, even if only for a single item rather than embed a simple sql select in a calculation. (I thought I read in one post that keeping down the number of relationships is a good idea with regard to solution speed and loading times, so I was looking for alternatives where a relationship is only required for one item).
an embedded sql will always really do a query to the database.
And you have no control over when a calculation is calculated. So this will be expenisve.
A relation will be much faster because we can handle the db access and cache when we can.