Need a help in display of Date and time format in the incident form

Thrupthi
Tera Expert

How to change the date format form 2018-07-20 07:37:35 to 20/07/2018 08:37:35.

I have created script include and client script for UTC end field. UTC end will display the GMT date and time automatically when we select the Incident End date and time. But here when I select the Incident date, UTC end date and time is displaying in different format. please can somebody help on how to display the date format in 20/07/2018 08:37:35.

Client Script:

var ga = new GlideAjax('PGIncidentAJAX');
ga.addParam('sysparm_name', 'getGMT');
ga.addParam('sysparm_date_time', newValue);
ga.getXML(processResponse);

function processResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_utc_end', answer); 
}

 

Server Script:

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

getGMT: function(){
var dt = this.getParameter('sysparm_date_time');
var gmt = new GlideDateTime();
// gmt.setStringParameter(dt.getByFormat("dd/MM/yyyy"));
gmt.setDisplayValue(dt);
return gmt;
},
type: 'PGIncidentAJAX'
});

 

 

1 ACCEPTED SOLUTION

I test below in my Dev instance and worked.

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

	getGMT: function(){
		var dt = this.getParameter('sysparm_date_time');
		var gdt = new GlideDateTime();
		gdt.setDisplayValue(dt);
		var date = gdt.getValue().split(' ');
		var dateonly = new GlideDate();
		dateonly.setValue(date[0]);
		var last = dateonly.getByFormat('dd/MM/yyyy') + " " + date[1];
		return last;
	},
	type: 'PGIncidentAJAX'
});

 

View solution in original post

20 REPLIES 20

Chuck Tomasi
Tera Patron

The date/time format is a system setting. Users can override it with their personal profile. It is not something you configure per form/table. That could lead to confusion if it were different throughout the system.

I recommend starting here to review how date/time is configured if you need more information:

Docs: Global date and time field format

But we only need this to be done on the incident form 

find_real_file.png

Mike Patel
Tera Sage

How are you changing format for UTC start ?

We havent written any script for UTC start Mike, its just taking the system defined date.