- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 02:15 PM
I have what looks to be a simple client script that is passing a date to script include though GlideAjax.
I pass the date into a GlideDateTime and then return the getDisplayValue() to the Client Script.
In the Client script I alert the date, but the date is now different from the one I collected from the form. I did not manipulate the date at all why is it different returning from the script include?
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// if (oldValue == '') {
var newDate = g_form.getValue('adjusted_deployment_start');
alert(newValue);
alert(newDate);
var ga = new GlideAjax('ApacClientHelper');
ga.addParam('sysparm_name', 'calcAdjustedDeploymentEnd');
ga.addParam('sysparm_date', newDate);
ga.getXMLAnswer(updateEndDate);
// }
}
function updateEndDate(answer) {
var returnedDate = answer;
alert(answer);
}Script Include
calcAdjustedDeploymentEnd: function() {
var gdt = new GlideDateTime(this.getParameter('sysparm_date'));
return gdt.getDisplayValue();
},The first two alerts on the client script show the correct time entered into the field
The Third alert after the script include is not the same time anymore
Additional Details: The time has been adjusted by -7 hours, and that is our timezone UTC-7. And our system default timezone is UTC-7 as well.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 09:45 AM - edited 11-09-2023 09:48 AM
Hi @Calvert
So let's try these variables g_user_date_time_format and g_user_date_format.
var resolved_date_time = getDateFromFormat(g_form.getValue('resolved_at'), g_user_date_time_format);
var objResolvedDate = new Date(resolved_date_time);
objResolvedDate.setHours(objResolvedDate.getHours() + 3); //+3 hours
var new_resolved_date_time = formatDate(objResolvedDate, g_user_date_time_format);
You can also convert to system format and pass to the Script Include to calculate.
var resolved_date_time = getDateFromFormat(g_form.getValue('resolved_at'), g_user_date_time_format);
var objResolvedDate = new Date(resolved_date_time);
var new_resolved_date_time = formatDate(objResolvedDate, "yyyy-MM-dd hh:mm:ss");
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 06:35 AM
I want to add 3 hours to the date/time and return it. But I started with just returning the same date/time to test.
Also it needs to return the correct time regardless of the timezone or date format (dd/mm/yyyy or mm/dd/yyyy) the user is in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 03:01 PM
Hi @Calvert
Try this in your Script Include. It will give you the correct results:
calcAdjustedDeploymentEnd: function() {
var gdt = new GlideDateTime();
return gdt.setDisplayValue(this.getParameter('sysparm_date'));
},
Thanks!
Mark it as helpful if it works 🙂
