.getDay is not a function?

Questions, tips and tricks and techniques for scripting in Servoy

.getDay is not a function?

Postby Ron » Tue Feb 03, 2004 8:29 pm

The following loop generates a certain amount of records with ascending dates in field: mdate. All works fine without the last line of code: mday=b.getDate()
I put I get the error: getDate is not a function.
First I thought I had to save the data first, but that was not the case.
What do I wrong?

for ( var i = 1 ; mdate < globals.genddate ; i++ )
{
controller.newRecord();
var a= globals.gstartdate;
var b= a.setDate(a.getDate()+i);
mdate=b;
mday=b.getDate();
}
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Postby IT2Be » Tue Feb 03, 2004 9:44 pm

Code: Select all
var a= globals.gstartdate;

I assume a = Date?
Code: Select all
var b= a.setDate(a.getDate()+i);

This way b = integer!!!!
Code: Select all
mday=b.getDate()

So this won't work...

BTW for testing/debugging "application.output(a+"-"+b);" is very much capable to help you :)
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby maarten » Tue Feb 03, 2004 10:06 pm

1) b indeed becomes an integer
2)should'nt you declare "var a" outside your looop?

try this:
var a= globals.gstartdate;
for ( var i = 1 ; mdate < globals.genddate ; i++ )
{
controller.newRecord();
a.setDate(a.getDate()+i);
mdate=a;
mday=a.getDate();
}
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby Ron » Tue Feb 03, 2004 11:49 pm

Thanks for your replies guys.
I concentrate this time on the basic things.
The following script runs OK:

for ( var i = 1 ; mdate < globals.genddate ; i++ )
{
controller.newRecord();
var a= globals.gstartdate;
mdate=a.setDate(a.getDate()+i);
}

This one, in which : var a=globals.gstartdate
is put outside the loop as Maarten suggested, NOT:
It loops only 27 times out of 366.
The fieldvalue mdate is not set properly so it seems.

var a= globals.gstartdate;
for ( var i = 1 ; mdate < globals.genddate ; i++ )
{
controller.newRecord();
var a= globals.gstartdate;
mdate=a.setDate(a.getDate()+i);
}


This is realy strange I think.
Apart from this the question remains how to set the mday field?
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Postby maarten » Wed Feb 04, 2004 11:33 am

Code: Select all
var a= globals.gstartdate;
for ( var i = 1 ; mdate < globals.genddate ; i++ )
{
controller.newRecord();
var a= globals.gstartdate;
mdate=a.setDate(a.getDate()+i);
}


1) var a= globals.gstartdate; is declared twice.
2) mdate=a.setDate(a.getDate()+i);
you're trying to set datefield(?) mdate with an integer.
a.setDate(a.getDate()+i) returns an integer
3) for ( var i = 1 ; mdate < globals.genddate ; i++ )
Seems to me you first have to define the foundset you want to loop through:
-search for all records that have mdate < globals.genddate
- then do for ( var i = 1 ; i< controller.getMaxRecordIndex(); i++ )


So here's how I would do it:

Code: Select all
//search for all records that have mdate < globals.genddate
//in order to define the foundset you are going to loop through.
var a= globals.gstartdate; //declare dateObject a only once
for ( var i = 1 ;  i<= controller.getMaxRecordIndex(); i++ )
{
   controller.newRecord(); //IMPORTANT: create your records in an other table then the one you are looping through, otherwise your loop will never stop. (i will always be smaller then controller.getMaxRecordIndex()
   a.setDate(a.getDate()+1); //increase a(dateObject) with one day
   mdate= a //set mdate(datefield) with (a)(dateObject)
   mday = a.getDate(); //set mday(integer field)  with a.getDate()(integer result)
}
Last edited by maarten on Wed Feb 04, 2004 11:54 am, edited 1 time in total.
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby maarten » Wed Feb 04, 2004 11:52 am

looking at your global startDate and global endDate
don't you just want to create records between those two dates?

Code: Select all
var a= globals.gstartdate;
while (  a < globals.genddate )
{
   controller.newRecord();
   a.setDate(a.getDate()+1);
   date_followup = a
   nr = a.getDate();
}
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby Ron » Wed Feb 04, 2004 11:06 pm

Thanks a lot Maarten, I will have a close look at your replies.
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 29 guests

cron