- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 01:45 AM
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!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 03:40 AM
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
www.dxsherpa.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 01:47 AM
Hi
Show me the way you have written the macro.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 01:53 AM
This should be a minimal example of what I'm trying to do:
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<j:set var="jvar_n" value="suggest_${ref}"/>
<a id="${jvar_n}" onclick="get_common_data('${ref}')" title="suggestion" alt="suggestion" tabindex="0" class="btn btn-default icon-lightbulb">
<a class="sr-only">suggestion</a>
</a>
<script>
function get_common_data(foo) {
var data = {};
data["==user_id=="] = "${gs.getUser().getID()}";
data["==unixtime_ms=="] = "${GlideDateTime().getNumericValue()}";
return data
}
</script>
</j:jelly>

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 01:52 AM
can you try with glide ajax.
create a client callable script include and use glide date time method to return current date and time. then in ui macro "client script" use that function to save the function output through glide ajax . this way you can solve your requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2018 02:41 AM
Hi, can you elaborate on how to invoke the client callable script to fit the code I pasted above? I have created the following client callable include script:
var MyGetDate = Class.create();
MyGetDate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize :function(){},
getDate: function(){
return new GlideDateTime().getNumericValue();
},
type: 'MyGetDate'
});
If in my UI macro I try to do:
var dt = new MyGetDate();
data["==unixtime_ms=="] = dt.getDate();
It does not work.