Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

GlideDateTime not working in Script Include

SN_Learn
Kilo Patron
Kilo Patron

Hi All,

 

I am passing dateTime field from client script to script Include and in the script include I am adding days in that dateTime field which is setting restting my time to 00:00:00

 

 

 

onChange Client Script
-----------------------------

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var getRepeatVal = g_form.getValue('repeat'); 
    var actualStart = g_form.getValue('start_time'); //DateTime
    var actualEnd = g_form.getValue('end_time'); //DateTime
	
    alert(actualStart);

    if (getRepeatVal == 'Daily') {

        var ajax = new GlideAjax('IncScriptUtil');
        ajax.addParam('sysparm_name', 'dataCheck');
        ajax.addParam('sysparm_act_start', actualStart);
        ajax.addParam('sysparm_act_end', actualEnd);
        ajax.getXML(validateConflict);
    }
}

function validateConflict(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);
}

 

 

 

 

 

Script Include
------------------


dataCheck: function() {
        var actualStart = this.getParameter('sysparm_act_start'); //24/05/2024 09:20:51
        var actualEnd = this.getParameter('sysparm_act_end');
      
         var getActualDate = actualStart.addDays(1); 
         gs.log(getActualDate); //25/05/2024 01:00:00
         return true;

    },

 

 

Here, It should print '25/05/2024 09:20:51' but it is not doing it.

Could you please assist how could I preserve my time as it is? 

 

Thanks.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.
1 ACCEPTED SOLUTION

dgarad
Giga Sage

Hi @SN_Learn 

modified the script include .

var actualStart = this.getParameter('sysparm_act_start'); //24/05/2024 09:20:51
        var actualEnd = this.getParameter('sysparm_act_end');

var date = new GlideDateTime();
date.setDisplayValue(actualStart);
  date.addDays(1); 
 gs.log(date); //25/05/2024 01:00:00
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

View solution in original post

5 REPLIES 5

Viraj Deshmukh
Tera Expert

DId you return the "getActualDate " variable from the script include to client script ?

Hi Viraj, No I didn't. I used return true in ScriptInclude and to run the client script. For testing I used logs in script include.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

dgarad
Giga Sage

Hi @SN_Learn 

modified the script include .

var actualStart = this.getParameter('sysparm_act_start'); //24/05/2024 09:20:51
        var actualEnd = this.getParameter('sysparm_act_end');

var date = new GlideDateTime();
date.setDisplayValue(actualStart);
  date.addDays(1); 
 gs.log(date); //25/05/2024 01:00:00
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Thanks @dgarad , It worked!

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.