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

Kalaiarasan Pus
Giga Sage

Define a script include and use below method to add time. Call the script in reference qualifier


gdt.addSecondsLocalTime



Ex: Modify a GlideDateTime Field Value - ServiceNow Wiki


Hi kalai,



Field type is Data/time.


I can not see any reference qualifier for this filed. Please guide me what need to be done.



Thanks & Regards


Govind Kumar Sharma


My bad.. Its default value


neetusingh
Giga Guru

For End date, enter the default value   - javascript:gs.hoursAgo(-36);