- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:45 AM
Hi All,
I have a requirement where i have to auto populate a date field based on the field ('information' - field type is checkbox). If the checkbox is checked then populate today date in the date field.
How can i achieve this, please help.
Thanks in Advance,
SD.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:52 AM
Please check this as well.
Name: Set Current Date/Time In Field
Type: Client Script
Table:
Description: You can use the following two lines to set the current date and time in a date/time field. This bypasses the problem of getting the value into the proper format and proper timezone:
Parameters:
Script: For more information on running Server Side Script with the client please refer to GlideAjax.
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(function () { g_form.setValue('put your field name here', ajax.getAnswer()); });
System Script Include
// Be sure the "Client callable" checkbox is checked var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, { nowDateTime: function () { return gs.nowDateTime(); }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:48 AM
you can achieve it by onChnage cleint script on that check box.
if it's checked then set the today's date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:52 AM
Hi Shishir,
Could you please give me sample script?
Thanks,
SD

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 10:55 AM
let me get that.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2017 11:05 AM
Please try below.
onChange client script on you checkbox,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
if(<your checkbox field name>== true)
{
g_form.setValue('your field name', answer);
}
}
}
script include:
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
nowDateTime: function () {
return gs.nowDateTime();
},
type: 'MyDateTimeAjax'
});