- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 05:47 AM
Why in Script Includes, using the .setDayOfMonthUTC(int) method on GlideDateTime(datetime) objects return undefined, while it's working okay outside of the Script Include?
What I run in the Scripts - Background module:
var util = new u_gdt();
var date = util.dateDebug('2020-04-22 21:07:27');
var dt = new GlideDateTime('2020-04-22 21:07:27');
gs.info("var dt = new GlideDateTime(date): "+dt);
dt.setDayOfMonthUTC(1);
gs.info("dt.setDayOfMonthUTC(1): "+dt);
The Script Include is as follows:
var u_gdt = Class.create();
u_gdt.prototype = {
initialize: function() {},
dateDebug: function(dateTime) {
var service_date = new GlideDateTime(dateTime);
var now = new GlideDateTime();
gs.info([, "service_date = new GlideDateTime(dateTime): " + service_date,
"service_date.isValid(): " + service_date.isValid(),
"service_date.getDaysInMonthUTC(): " + service_date.getDaysInMonthUTC(),
"service_date.setDayOfMonthUTC(1): " + service_date.setDayOfMonthUTC(1),
"now = new GlideDateTime(): " + now,
"now.setDayOfMonthUTC(1): " + now.setDayOfMonthUTC(1)
].join('\n'));
return service_date;
},
type: 'u_gdt'
};
Returns when ran:
*** Script:
service_date = new GlideDateTime(dateTime): 2020-04-22 21:07:27
service_date.isValid(): true
service_date.getDaysInMonthUTC(): 30
service_date.setDayOfMonthUTC(1): undefined
now = new GlideDateTime(): 2020-04-21 12:42:54
now.setDayOfMonthUTC(1): undefined
*** Script: var dt = new GlideDateTime(date): 2020-04-22 21:07:27
*** Script: dt.setDayOfMonthUTC(1): 2020-04-01 21:07:27
Compare the returns of service_date. / now.setDayOfMonthUTC(1) and dt.setDayOfMonthUTC(1).
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 06:09 AM
It's been my mistake!
When I ran it out of the Script Include, I first ran the method, and then misleadingly echoed the object to the console in a separate call:
dt.setDayOfMonthUTC(1);
gs.info("dt.setDayOfMonthUTC(1): "+dt);
//vs:
gs.info("dt.setDayOfMonthUTC(1): "+dt.setDayOfMonthUTC(1));
The latter line results in the same behavior, returning undefined - and that's actually in the docs after all:
https://developer.servicenow.com/dev.do#!/reference/api/newyork/server/no-namespace/c_APIRef#r_ScopedGlideDateTimeSetDayOfMonthUTC_Number_day
Return:
Type | Description |
---|---|
void | Method does not return a value |

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 05:51 AM
Does your script includes have Client Callable checked?
If yes, you need to remove the line below:
initialize: function() {},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 05:58 AM
Hi Michael,
That's a good guess, but Client Callable is unchecked. I created this script on my PDI after I noticed this behavior on a consumer instance.
Just to be sure, I've toggled the checkmark and removed the line like you suggested, but the behavior's still the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2020 06:09 AM
It's been my mistake!
When I ran it out of the Script Include, I first ran the method, and then misleadingly echoed the object to the console in a separate call:
dt.setDayOfMonthUTC(1);
gs.info("dt.setDayOfMonthUTC(1): "+dt);
//vs:
gs.info("dt.setDayOfMonthUTC(1): "+dt.setDayOfMonthUTC(1));
The latter line results in the same behavior, returning undefined - and that's actually in the docs after all:
https://developer.servicenow.com/dev.do#!/reference/api/newyork/server/no-namespace/c_APIRef#r_ScopedGlideDateTimeSetDayOfMonthUTC_Number_day
Return:
Type | Description |
---|---|
void | Method does not return a value |