Fetching current date and time from onclick UI Macro

mstockel
Kilo Contributor

Hi SN community, 

I have a UI macro that is invoked when a particular button is pressed. When this happens, I send some data to a webserver, and one of these data poubts is the current time and date according to the servicenow instance, I have tried to do it the following way:

data["==unixtime_ms=="] = "${new GlideDateTime().getNumericValue()}";

however, it seems the expression is only evaluated when I update the UI macro, and not OnClick as I want. How do I crate a new GlideDateTime object on each onclick event in a UI macro? Help much appreciated!

1 ACCEPTED SOLUTION

Hi 

it seems you have done something wrong while creating script include.

Create a new one with client callable tick and do this. 

and check if this script include is for all application scopes i.e Global.

var getdate = Class.create();
getdate.prototype = Object.extendsObject(AbstractAjaxProcessor, {

type: 'getdate'
});

This type of Script include is created when client callable is true. 

 

Mark Correct if it helps.

Warm Regards,

Omkar Mone

find_real_file.png

www.dxsherpa.com

View solution in original post

12 REPLIES 12

can you put the log also remove the initialize 

Hi both, I got it working. Either my initialize function messed it up or something was wrong with how the script was set up. Thanks

glad it worked.

Please mark the answer correct and close this thread.