I know how to pass parameters to a method, but once passed, how can they be referenced again in the calling method?
For example, I pass date parameters to a global method that calculates new dates such as:
var fromdate = null
var todate = null
globals.setFromToDates(60, fromdate, todate)
globals.TEEntryFromDate = fromdate
globals.TEEntryToDate = todate
todate wil be set to todays date, fromdate will be set to 60 days before todate.
Global method looks like this:
//setFromToDates[globals]
// this method will set date parameters
// todate set to today’s date
// fromDate set to arguments[0] days before today’s date
var days = arguments[0]
if (! days )
{
days = 4330
}
daysms = days1000606024
var todate = new Date()
fromdate = todate - daysms
return (fromdate, todate)
When I return from globals.setFromToDates() method fromdate and todate are still null, even though they are set correctly in global method. Since they are referenced in the return statement I assumed they would be available in the calling method, but obviously not. What is the proper syntax? I would rather not use global variables for these values.
DFehrenbach:
var fromdate = null
var todate = null
globals.setFromToDates(60, fromdate, todate)
globals.TEEntryFromDate = fromdate
globals.TEEntryToDate = todate
The last 2 lines here are not needed.
//setFromToDates[globals]
// this method will set date parameters
// todate set to today’s date
// fromDate set to arguments[0] days before today’s date
var days = arguments[0]
if (! days )
{
days = 4330
}
daysms = days1000606024
var todate = new Date()
fromdate = todate - daysms
return (fromdate, todate)
instead of return(fromdate, todate) put the global definitions here
globals.TEEntryFromDate = fromdate
globals.TEEntryToDate = todate
The globals will be availible to you in the calling method.
That should do it, but if you MUST use a return statement try this:
I believe return is only capable of returning one object. You could make that object be an array of values.
return (var daterangearray[fromdate, todate])
not sure on that array code syntax!
globals.setFromToDates(60, fromdate, todate)
globals.TEEntryFromDate = fromdate
globals.TEEntryToDate = todate
If you are using return() then you have to capture the returned object;
try:
var daterangearray = globals.setFromToDates(60, fromdate, todate)
todate = daterangearray[0]
fromdate = daterangearray[1][/code]
Thanks for the info. I do need to pass parameters back to the calling method because I execute the global method from many other forms and methods, and the global from and to dates change depending on where they are called.
Your advice to code the method as function did the trick
BTW the correct syntax for the array is:
var array = new Array (fromdate, todate)
Thanks again for all your help!