The Now Platform® Washington DC release is live. Watch now!
‎02-01-2018 09:12 AM
I have a weird issue between dev and prod instances. I have created a monthly scheduled job to run every three months:
var gdt = new GlideDate();
var mth = gdt.getMonth();
if (mth == 1 || mth == 4 || mth == 7 || mth == 10) { // Feb, May, Aug, Nov
answer = true
}
else {
answer = false;
}
In dev, this does not run despite the month being February (1). However, in prod, it runs just fine.
In dev, I changed the months in the condition to this:
if (mth == 0 || mth == 2 || mth == 6 || mth == 9)
It worked!
I then ran the following script as a background to confirm what mth was:
var gdt = new GlideDate();
var mth = gdt.getMonth();
gs.info(mth);
The output was: 2 (March?)
I then ran this:
var gdt = new Date();
var mth = gdt.getMonth();
gs.info(mth);
The output was 1 (February?)
This is the case in both instances.
So, why does the script work in prod and not in dev?
Why when I change the month in the condition does it work in dev?
What is the difference between Date and GlideDate?
Solved! Go to Solution.
‎02-01-2018 09:29 AM
Hi Wayne,
That is how it's defined, If you use the GlideRecord (OOB Service now GlideRecord API) for getMonth() then it provides the numeric value of Months starting from 1 to 12: GlideDateTime - Global
GlideDateTime - getMonth()
Gets the month stored by the GlideDateTime object, expressed in Java Virtual Machine time zone.
Returns
Type Description
Number The numerical value of the month, Jan=1, Dec=12.
But in general if you use the Javascript getMonth() function then it provides the numeric value of Months starting from 0 to 11.: JavaScript getMonth() Method
The getMonth() method returns the month (from 0 to 11) for the specified date, according to local time.
Please check the provided links for more details.
‎02-01-2018 09:17 AM
Hi Rich,
GlideDate is server date provide by service-now
new Date() is javascript date
‎02-01-2018 09:20 AM
‎02-01-2018 09:22 AM
I think date and time format difference is dev and prod instance can you check.
‎02-01-2018 09:28 AM
They are both dd-MM-yy