UI Policy script to make a field autopopulate current date and time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2016 02:02 PM
Hi,
I want to make a field auto populate current date and time using UI policy. Depending on other field. Please advice.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2016 02:21 PM
Use a client script and then use GlideAjax in the client script to get the current date time from the server. Let me know if you need any help in scripting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2016 02:24 PM
Thanks Abhinay,
There is a choice field: so if choice = New then in other field it should populate current date and time. Can you please help in code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2016 02:27 PM
Only if choice is new, current date should be set?
If so, (Untested Code)
Client Script Type:onChange
Field: your choice field
script:
if(newValue == 'New'){
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.getXML(function () {
g_form.setValue('put your field name here', ajax.getAnswer());
});
}
Use the same Script Include as in the article.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2016 02:40 PM
write a script include : It should be client callable
var MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
nowDateTime: function () {
return gs.nowDateTime();
In your client script: Onchange of filed name
check if condition: if type of choice field = new
{
var ajax = new GlideAjax('script include name');
ajax.addParam('sysparm_name', 'script include function name');
ajax.getXML(something);
function something(resp) {
var answer=resp.responseXML.documentElement.getAttribute("answer");
g_form.setValue('filed',answer);
}
}