How to set date/time field

Govind Kumar S1
Kilo Guru

Hi All,

I have two Date/Time field in service catalog form.

1. start date/time        

2.End date/time

I want to set start date as current date and time. I have achieved this using javascript:gs.nowDateTime();

find_real_file.png

for end date/time field , I want the value as start date/time + 36 Hours.

How can I achieve this , Please guide me on this.

Appreciate every Comment on this post.:)

Thanks & Regards

Govind Kumar Sharma

1 ACCEPTED SOLUTION

Govind Kumar S1
Kilo Guru

Hi All ,



Thanks for reply .



I got solution for this requirement. Client Script Date/Time Functions .


function onLoad() {

var cdt = g_form.getValue('startdate'); //Choose the field to add time from  

var addtime = 36; //The amount of time to add  
var addtype = 'hour'; //The time type.   Can be second, minute, hour, day, week, month, year.  
 
var ajax = new GlideAjax('ClientDateTimeUtils');  
ajax.addParam('sysparm_name', 'addDateTimeAmount');  
ajax.addParam('sysparm_fdt', cdt);  
ajax.addParam('sysparm_addtime', addtime);  
ajax.addParam('sysparm_addtype', addtype);  
ajax.getXML(doSomething);  


function doSomething(response){  
  var answer = response.responseXML.documentElement.getAttribute("answer");  
    //You could then take the new Date/Time answer and set the value of another field.  
    // g_form.setValue('expected_start', answer);  
//g_form.enddate.setDisplayValue(answer);
alert("enddate :" +answer);  
g_form.setValue('enddate', answer);
}  


 

}



Thanks & Regards


Govind Kumar Sharma


View solution in original post

8 REPLIES 8

hoursago will use system time and not user time? Correct?


Hi Kalai,



You are right. it is using system time.



When I am changing time zone, Start date/time field is changing accordingly but End Data/time is not changing.



Thanks & Regards


Govind Kumar Sharma


Hi Neetu,



It is using System time. when I am changing time zone end date/time field is not changing accordingly.



Thanks & Regards


Govind Kumar Sharma


Govind Kumar S1
Kilo Guru

Hi All ,



Thanks for reply .



I got solution for this requirement. Client Script Date/Time Functions .


function onLoad() {

var cdt = g_form.getValue('startdate'); //Choose the field to add time from  

var addtime = 36; //The amount of time to add  
var addtype = 'hour'; //The time type.   Can be second, minute, hour, day, week, month, year.  
 
var ajax = new GlideAjax('ClientDateTimeUtils');  
ajax.addParam('sysparm_name', 'addDateTimeAmount');  
ajax.addParam('sysparm_fdt', cdt);  
ajax.addParam('sysparm_addtime', addtime);  
ajax.addParam('sysparm_addtype', addtype);  
ajax.getXML(doSomething);  


function doSomething(response){  
  var answer = response.responseXML.documentElement.getAttribute("answer");  
    //You could then take the new Date/Time answer and set the value of another field.  
    // g_form.setValue('expected_start', answer);  
//g_form.enddate.setDisplayValue(answer);
alert("enddate :" +answer);  
g_form.setValue('enddate', answer);
}  


 

}



Thanks & Regards


Govind Kumar Sharma