Setting a default time in a date/time field using a client script.

m_ahmedmod
Giga Contributor

Hi,

I'm trying to set a default date and time in a time/date field using a client script, it should be set to todays date and a time of 5pm. Does anyone have an idea on how this might be possible.
I thought it might look like this but it doesn't seem to work:

function onLoad() {
g_form.setValue('start_date',gs.now()+' 17:00:00');
}

Thanks in advance.

8 REPLIES 8

Thank you Shishir Srivastava !! It worked for me


Hi SNOW Istanbul


can u pls write a business rule for this



(function executeRule(current, previous /*null when async*/) {


var work_start = current.work_start;//pls adjust ur requirement field   names here  


var gdt = new GlideDateTime(work_start);


var current_date = gs.now();


gdt.addDays(7);


var lead_date = gdt.getDate();


gs.addInfoMessage(lead_date);


gs.addInfoMessage(current_date);


if(current_date>=lead_date){


gs.addInfoMessage('updated');



}


else{


gs.addInfoMessage('Please wait for 7 days for implememtation' );


current.setAbortAction(true);


}


preddy
Kilo Guru

Hi ahmed,


Simple way you can go to the field Dictionary in Default Value use this script: javascript:gs.now() + " 17:00:00 ";



Bye Default it tooks the current Date and Time 5PM.



PS: Hit like, Helpful or Correct depending on the impact of the response.


The Dave Carrol
Giga Contributor

nice one Admed! this works like a charm.