- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 03:46 AM
Hi Every one,
getNumericValue() is not working, below is the script.
var start_date = new GlideDateTime();
var end_date = '04-02-2020 07:30:00';
gs.print(start_date.getNumericValue());
gs.print(end_date.getNumericValue());
gs.print(new GlideDateTime());
result:
*** Script: 1585737978939
*** Script: undefined
*** Script: 2020-04-01 10:46:18
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 04:00 AM
Hi,
You can try this script.
var start_date = new GlideDateTime();
var end_date = new GlideDateTime("2020-02-04 07:30:00");
gs.print(start_date.getNumericValue());
gs.print(end_date.getNumericValue());
gs.print(new GlideDateTime());
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 03:52 AM
Hello Sanjeeva ,
I had same issue few days back so I used this script to resolve👇
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var nbrwn = g_form.getIntValue('port_number');
//check to see if there are any non numeric characters in the string
if ((isNaN(newValue) == true) || (nbrwn < 0)) {
alert("Please enter a numeric value for Port Number");
g_form.setValue('port_number', '');
}
}
Hope this will help you 🙂
if my response helps you then kindly mark my answer helpful 👍and correct ✔otherwise if any query feels free to ask further.
Regards,
Ajim.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 04:00 AM
Hi,
You can try this script.
var start_date = new GlideDateTime();
var end_date = new GlideDateTime("2020-02-04 07:30:00");
gs.print(start_date.getNumericValue());
gs.print(end_date.getNumericValue());
gs.print(new GlideDateTime());
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 04:06 AM
Hi,
You are assigning the value to end_date which is consider as a string not as a date/time.
The getNumericValue() returns number of milliseconds since January 1, 1970, 00:00:00 GMT.
Their is a small change in your script.
If my response is helpful to you, please make it correct or helpful.
Thanks
Bhagyashri Sorte

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2020 04:12 AM
Hi
first store it in variable the print :
example:
data.mydate = mydate.getNumericValue();
if not then go through the following thread:
https://community.servicenow.com/community?id=community_blog&sys_id=f5ac2625dbd0dbc01dcaf3231f961929
If it help mark helpful or correct
Thanks and regards
Anil