GlideDate() is working in client Script, however the requirements should be in GlideDateTime (). Is there anyone who can assist me with this?

Ashoka Panchal
Tera Contributor

var recPriority = g_form.getValue('u_rec_rating');
var cdt = new Date();  // When I use GlideDateTime() it's showing error.
var addtime;
var addtype = 'day';
if (recPriority == '2') {

addtime = 7; //The amount of time to add
}
if (recPriority == '3' || recPriority == '4') {

addtime = 90; //The amount of time to add

}

var ajax = new GlideAjax('global.ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'addDateAmount');
ajax.addParam('sysparm_fdt', cdt);
ajax.addParam('sysparm_addtime', addtime);
ajax.addParam('sysparm_addtype', addtype);
ajax.getXML(doSomething); //Need callback function

function doSomething(response) {
//Sets field
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('due_date', answer);

Current Result:  find_real_file.png

Expected : DateTime

15 REPLIES 15

Anil Lande
Kilo Patron

Hi,

Why don't you use GlideDateTime in Script include function. Instead of passing parameter from Client script, you can skip it and use GlideDateTime API in script include function for calculations.

 

Thanks
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

I've used GlideDateTime in Script include, it's throwing an error. 

find_real_file.png

Chetan Mahajan
Kilo Sage
Kilo Sage

Hi Ashoka,

                   refer below code in your script include

check_probation: function() {

        var prob = this.getParameter('sysparm_value'); // to get parameter from client side in your case recPriority 
        var today = new GlideDateTime();
        if (prob == 'true') {
            today.setDisplayValue(today.addDays(30));
        }
        if (prob == 'false') {
            today.setDisplayValue(today.addDays(90));
        }
        return today.getDisplayValue();

    },

Chetan Mahajan
Kilo Sage
Kilo Sage

Hi Ashoka,

                     Can you share your script include as well ?