Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Add Incident "Date and time" field in ServiceNow

Supriya Jadhav
Tera Contributor

In order to allow more efficient investigations of incidents raised by colleagues, a new mandatory field should be added to incident form. The field created should be a standard date and time field with a "Now" button to enter a current date and time. However, the fields should not be pre-populated. How can I achieve this requirement?

1 ACCEPTED SOLUTION

Sagar Pagar
Tera Patron

Hi @Supriya Jadhav,

You have to add new custom date-time field on incident form. Also, add "Now" UI action on Incident table.

 

scripts -

 

current.u_date_time_field = new GlideDateTime();

current.update();

 

 

OR

current.u_date_time_field = gs.now();

current.update();

 

 

Thanks,
Saagr Pagar

 

 

The world works with ServiceNow

View solution in original post

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @Supriya Jadhav,

You have to add new custom date-time field on incident form. Also, add "Now" UI action on Incident table.

 

scripts -

 

current.u_date_time_field = new GlideDateTime();

current.update();

 

 

OR

current.u_date_time_field = gs.now();

current.update();

 

 

Thanks,
Saagr Pagar

 

 

The world works with ServiceNow

reshmapatil
Tera Guru

Hi @Supriya Jadhav ,

 

1. You can have UI Action and save date/time to the database:

reshmapatil_0-1671468554908.png

getCurrentDateTime();

function getCurrentDateTime() {
current.u_current_date_time = new GlideDateTime();
current.update();
action.setRedirectURL(current);


}

 

2. Populate the current date/time on a field using client-callable UI Action:

reshmapatil_1-1671469998688.png

//Client-side 'onclick' function
function runClientCode() {
var ajax = new GlideAjax('ClientDateTimeUtils');
ajax.addParam('sysparm_name', 'getNowDateTime');
ajax.getXML(doSomething);
}

function doSomething(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_current_date_time', answer);

gsftSubmit(null, g_form.getFormElement(), 'get_current_date_time'); //MUST call the 'Action name' set in this UI Action
} //Code that runs without 'onclick'

if (typeof window == 'undefined')
runBusRuleCode();

//Server-side function
function runBusRuleCode() {

action.setRedirectURL(current);
}

reshmapatil_2-1671470033066.png

var ClientDateTimeUtils = Class.create();
ClientDateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

//Returns the Date/Time of right now.
getNowDateTime: function(){
var now = gs.nowDateTime(); //Now Date/Time
return now;
},

});

 

 

 

 

Regards,

Reshma

**Please mark my answer correct or helpful based on the impact**