The CreatorCon Call for Content is officially open! Get started here.

End Date in my client Script is getting set to incorrect time on the Ritm and record

ServNowDev
Tera Guru
var endofDay = new Date();
var dateEod = endofDay.setHours(17,0,0,0);

g_form.setValue('u_end_date', new Date(dateEod));

 

the output in the RITM is 2025- 10 - 10 00:00:00

on the catalog its 2025- 10 - 10 17:00:00

1 REPLY 1

Sarthak Kashyap
Tera Expert

Hi @ServNowDev ,

 

Can you please use GlideAjax in your Client script and create a script include and add below code in your script include 

 

Client Script 

function onLoad() {
    var ga = new GlideAjax('GetEndOfDay');
    ga.addParam('sysparm_name', 'getEndOfDay');

    ga.getXMLAnswer(function(response) {
        if (response) {
            g_form.setValue('u_end_date', response);
        }
    });
}

 

Script Include

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

    getEndOfDay: function() {
        // Create a GlideDateTime object for current date
        var gdt = new GlideDateTime();
        
        // Set time to 17:00:00 (5 PM)
        gdt.setHourLocalTime(17);
        gdt.setMinuteLocalTime(0);
        gdt.setSecondLocalTime(0);
        gdt.setMillisecondLocalTime(0);

        // Return display value (string)
        return gdt.getDisplayValue();
    }

});

 

Please mark my answer correct and helpful if this works for you

Thanks,

Sarthak