set current date using ui action

Sharique Azim
Kilo Sage

Hi all,

i am trying to set the current date(only )using the ui action button.i have created a custom button named 'delete'.Now i want to set the valid to   field in the knowledge form to   be set with today's date.

here is the part of the code:

var dat = new GlideDate();

  dat.setValue(gs.daysAgo(0));//(gs.endOfToday());

  current.valid_to=dat.getDisplayValue(); //gs.now()

gs.addInfoMessage(gs.now());

even the message is not working

4 REPLIES 4

Anurag Tripathi
Mega Patron
Mega Patron

make this a serverside ui action and dont use new Date(as its JavaScript functions and will pick the browser's date not server)


use this to get the date


http://wiki.servicenow.com/?title=GlideDateTime#GlideDateTime.28.29&gsc.tab=0


-Anurag

Mihir Mohanta
Kilo Sage

Can you share the screen shot of the ui action form that you have created?



Thanks,


Mihir


Mohammed Lais1
Mega Guru

Hi sharique,



use this two lines in your ui action code



current.setValue('valid_to',gs.now());


current.update();


vamsi
Tera Contributor

Hi Azim,



First thing is your field "valid_to" must be a Date Field it should not be Date Time Field (Field Type).


Check your UI action code whether it is enclosed in a function and will be called when UI Action is clicked


if it is like that then your code won't be worked that way because onClick is a client side one so gs can't perform your requirement



If it is serverside I mean code is not enclosed in a client side onClick function you can just do the following and it'll work for sure:



current.valide_to=gs.now();


current.update();



gs.now() gives you Date with the format "MMM-DD-YYYY" (ex: Jun-08-2016) and if the target field is of Date type it'll update with current date.