- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 08:19 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 08:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 08:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2022 08:57 AM - edited 12-19-2022 09:15 AM
Hi @Supriya Jadhav ,
1. You can have UI Action and save date/time to the database:
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:
//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);
}
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**