getNumericValue() is not working.

Sanjeeva Nagend
Tera Contributor

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
1 ACCEPTED SOLUTION

Nootan
ServiceNow Employee
ServiceNow Employee

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

View solution in original post

5 REPLIES 5

Azim Kazi
Giga Guru

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.

Nootan
ServiceNow Employee
ServiceNow Employee

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

Bhagyashri Sort
Kilo Guru

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.

find_real_file.png

find_real_file.png

 

If my response is helpful to you, please make it correct or helpful.

 

      Thanks

Bhagyashri Sorte

 

 

Anil Shewale
Mega Guru

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