- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 10:58 PM
I want to display the current date on the Incident form as an alert.
Client Script:
function onLoad() {
var ga = new GlideAjax('GetDateTime');
ga.addParam('sysparam_name', 'date');
ga.getXMLWait();
var response = ga.getAnswer();
alert("Current Date: " + response);
}
Script Include:
var GetDateTime = Class.create();
GetDateTime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
date: function() {
var dt = new GlideDateTime();
var currentdate = dt.getDate().toString();
gs.info("Current Date Retrieved by GetDateTime: " + currentdate);
return currentdate;
},
type: 'GetDateTime'
});
In Alert i am getting Null.
Please help out with this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:44 PM
Hi @yuvarajkate ,
In client script by mistake you wrote
ga.addParam('sysparam_name', 'date');
instead of this use following line.
ga.addParam('sysparm_name', 'date');
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:44 PM
no script include and ajax required.
you can get it directly in onload client script
function onLoad(){
var selected_date = new Date(getDateFromFormat(new Date(), g_user_date_format));
var selected_dateStr = formatDate(selected_date, g_user_date_format);
alert(selected_dateStr);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2024 01:10 AM
Hi @yuvarajkate
change the client side code as below
ga.addParam('sysparm_name', 'date');
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2024 02:35 AM
To display the current date on the Incident form as an alert using GlideAjax, follow these steps. First, create a Script Include to fetch the current date. In the Script Include, write a server-side function that returns the current date. Make sure the Script Include is accessible from the client-side by setting the "Accessible from" field to Client callable
var CurrentDateUtils = Class.create();
CurrentDateUtils.prototype = {
initialize: function() {},
getCurrentDate: function() {
var currentDate = new GlideDateTime();
return currentDate.getDisplayValue();
},
type: 'CurrentDateUtils'
};
To display the current date on the Incident form as an alert using GlideAjax, follow these steps. First, create a Script Include to fetch the current date. In the Script Include, write a server-side function that returns the current date. Make sure the Script Include is accessible from the client-side by setting the "Accessible from" field to Client callable
function onLoad() {
var ga = new GlideAjax('CurrentDateUtils');
ga.addParam('sysparm_name', 'getCurrentDate');
ga.getXMLAnswer(function(response) {
var currentDate = response.responseXML.documentElement.getAttribute("answer");
alert('Current date is: ' + currentDate);
});
}
To display the current date on the Incident form as an alert using GlideAjax, follow these steps. First, create a Script Include to fetch the current date. In the Script Include, write a server-side function that returns the current date. Make sure the Script Include is accessible from the client-side by setting the "Accessible from" field to Client callable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:07 PM
Hi @yuvarajkate check below link have same requirement
https://www.servicenow.com/community/developer-forum/displaying-current-date-and-time/m-p/1484480
if my answer helps you mark helpful and accept solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:30 PM
Could you help me with this using Glide Ajax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:26 PM
Hi @yuvarajkate
Use below code :
function onLoad() {
var currentDate = new Date();
// Display an alert box with the current date and time
alert("The current date and time is: " + currentDate.toLocaleString());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2024 11:44 PM
Hi @yuvarajkate ,
In client script by mistake you wrote
ga.addParam('sysparam_name', 'date');
instead of this use following line.
ga.addParam('sysparm_name', 'date');
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi