I have a bit of code that I use to create a date range for searching. It uses two global date fields, datetime1 and datetime2.
It’s been in place for some time now and seemed to work fine. Since upgrading to 2.2, though, the times don’t get set. Has there been a change (intentional or otherwise) to the date functions?
Here’s the code:
controller.saveData();
// set datetime1 to the first second of the day.
var d1 = globals.datetime1;
d1.setHours(00);
d1.setMinutes(00);
d1.setSeconds(00);
var df1 = utils.dateFormat(d1, 'MM-dd-yyyy HH:mm:ss');
// set datetime2 out to the last second of that day.
var d2 = globals.datetime2;
d2.setHours(23);
d2.setMinutes(59);
d2.setSeconds(59);
var df2 = utils.dateFormat(d2, 'MM-dd-yyyy HH:mm:ss');
// parse all this into a queryString
globals.queryString = df1+'...' + df2+'|MM-dd-yyyy HH:mm:ss';
I could use the # for single dates, but I’d like it to work both ways, like this did up until I went to 2.2.
If there’s a shorter way to do what I’m doing, that’s great, and I’m interested, but that won’t fix the functions, or tell me how to properly use them when I need them.
The relevant point is this: setHours, etc. doesn’t seem to be working any more. Running this produces a queryString with unchanged times (set to zero for dates I’ve entered, and current time where I’ve set the current timestamp).
what if you have to do a global search with many variables
//Convert date range fields if not null
if (globals.Date1)
{
var d1 = globals.Date1
d1.setHours(00)
d1.setMinutes(00)
d1.setSeconds(00)
var df1 = utils.dateFormat(d1, ‘MM-dd-yyyy hh:mm:ss’)
}
if(globals.Date2)
{
var d2 = globals.Date2
d2.setHours(00)
d2.setMinutes(00)
d2.setSeconds(00)
var df2 = utils.dateFormat(d2, ‘MM-dd-yyyy hh:mm:ss’)
}
// validate date fields
if (globals.Date1 == null && globals.Date2)
{
plugins.dialogs.showInfoDialog(‘Warning’, ‘You must enter a start and end date’,‘OK’);
return
}
if (globals.Date2 == null && globals.Date1)
{
plugins.dialogs.showInfoDialog(‘Warning’, ‘You must enter a start and end date’,‘OK’);
return
}
//find, insert, search
controller.find()
// This code removes the operators from ship return date if there is no date criteria
if (globals.Date1 && globals.Date2)
{
shipping_date_returned = df1+ ‘…’ + df2 + ‘|MM-dd-yyyy hh:mm:ss’
}
else
{
shipping_date_returned = null
}
tracking_number = globals.Text1
transaction_type = globals.Text2
equipment_classification = globals.Text3
tse_number = globals.Text4
return_status = globals.Text5
inventory_id = globals.Integer1
account_id = globals.Integer2
if (globals.Text6) {
model = ‘%’ + globals.Text6 + ‘%’
}
application.closeFormDialog();
controller.search()
forms.CSMiscServicesSearchListing.controller.show()
globals.Number3 = controller.getMaxRecordIndex();
Not that this necessarily helps in this context but I have found that in
working with dates I really prefer to do almost everything directly in the
SQL backend database. In my case for instance I always need to have
today’s date at hand and bring up records based on that. After messing
around with the whole ’ 00:00:00’ and ’ 23:59:59’ stuff I found it easiest
to simply create a global today field when the user first logs in. Thus I do
the following in the global method in which g_Today is a global field set to
the default value ‘now’.
I could change the ’ 00:00:00’ into a global too (the ‘end’ time ’ 23:59:59’
for that matter) but haven’t bothered. In cases where you need a
dynamic value depending on the record/column selected a similar thing
can happen tied to onShow, onRecordSelection or whatever. For elapsed
time and ranges between dates I then use either the ‘datediff’ function or
‘BETWEEN’. The thing I felt was that Servoy was turning these things into
SQL statements anyway so one might as well do it straight away: less
code, fewer variables.
I have a report that uses the code I posted here. It’s in production and really needs to work. Can anyone suggest an alternative I could use until this is fixed?
The user enters a start and end date into globals.datetime1 and globals.datetime2, respectively.
I need to put those dates together into a string for searching the datetime in the form, which is formatted MM/dd/yyyy.
The string should find the range of dates, inclusive (including the end date).
I am not sure if I get this right. I have the same problem when passing a foundset from one method to another. If you do something like
var fs = foundset; // fs gets let's say a foundset of two records
controller.loadAllRecords() // now fs changes to the new foundset
I sort of see that I only passed a reference to an object “foundset” to fs somehow, but I don’t understand exactly why this happens and how you come around it. Unfortunately, I am not a studied programmer. If you have the time…