How to Set a glide_date_time to current time with a UI Action?

MG Casey
Mega Sage

My Goal:

User has button they can click to change a task's status to In Progress and the task's Start Date/Time field to the current time.

 

The first part has been easy to script, but my mind is exploding with how difficult the 2nd part has been. I have to be missing something easy.

 

My current UI Action script:

 

function startActivity() {

 

              g_form.setValue('u_status','1');        

              g_form.setValue('u_start_date_time',gs.now());

              gsftSubmit(gel('sysverb_update_and_stay'));

}

 

Right now, it only updates the Status field. I've tried sooo many different things. What am I missing to make that Start Date/Time simply equal the current time at the time of saving?

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage

Edit : use a server side button ....



current.u_status='1';


current.u_start_date_time=gs.now();


current.update();


action.setRedirectURL(current);


View solution in original post

4 REPLIES 4

harikrish_v
Mega Guru

gs.now() is actually server side code, so it wont work inside the client side function of your UI action. you need to use


current.u_stat_date_time=gs.now();


at server side to set the value. If you want to do it from client side, you can refer this wiki link:-



Set Current DateTime In Field - ServiceNow Wiki


Kalaiarasan Pus
Giga Sage

Edit : use a server side button ....



current.u_status='1';


current.u_start_date_time=gs.now();


current.update();


action.setRedirectURL(current);


Plus , if you want to do some client + server side processing using the same button , this would help



http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/


This was unbelievably easy - thank you.