set current date using ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 02:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 02:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 02:35 AM
Can you share the screen shot of the ui action form that you have created?
Thanks,
Mihir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 03:13 AM
Hi sharique,
use this two lines in your ui action code
current.setValue('valid_to',gs.now());
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2016 03:15 AM
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.