Portal Widget and DateTime Displaying UTC Instead of TimeZone

jlaps
Kilo Sage

Good afternoon community,

Finalizing a couple of portal pages I have been working on, and I have a question about pulling and displaying a datetime on a widget.

find_real_file.png

I am displaying the escalation date as above. I added the GMT at the end, because the datetime being shown is in GMT instead of either EST (system default) or user's timezone. Given how I am pulling this date, not sure where to fix it?

Server Script on widget for grabbing date-

if (data.table == 'incident') {
		 var escalatedinc = $sp.getField(rec, 'u_escalated_inc');
		 var incescaldate = $sp.getField(rec, 'u_escalate_date'); //added
		 var incescalby = $sp.getField(rec, 'u_escalated_by'); //added
	 data.escalatedby = incescalby;
	 data.escalated = escalatedinc;
	 data.escalatedate = incescaldate;	//added
	 }

Then on the HTML template, I am printing out the date on the widget-

<div class="row text-center">
             ${<h6>       
           <i>Escalated- } {{c.data.escalatedate.display_value}} GMT</i></h6>
         </div>

Given how I am populating the field, I am uncertain where to convert/fix the date. I am guessing I need to do so on the server script, pull out the display_value using a glidedatetime function and set it? 

What if I wanted to get fancy and have it convert to whatever was local for the viewing user?

Thanks for tips everyone.

Jeff

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

For server script you can try this:

if (data.table == 'incident') {
		 var escalatedinc = $sp.getField(rec, 'u_escalated_inc');
		 var incescaldate = $sp.getField(rec, 'u_escalate_date'); //added
		 var incescalby = $sp.getField(rec, 'u_escalated_by'); //added
	 data.escalatedby = incescalby;
	 data.escalated = escalatedinc;
         var gdt = new GlideDateTime();
         gdt.setValue(incescaldate);
	 data.escalatedate = gdt.getLocalTime();	//added
	 }

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

2 REPLIES 2

Allen Andreas
Administrator
Administrator

Hi,

For server script you can try this:

if (data.table == 'incident') {
		 var escalatedinc = $sp.getField(rec, 'u_escalated_inc');
		 var incescaldate = $sp.getField(rec, 'u_escalate_date'); //added
		 var incescalby = $sp.getField(rec, 'u_escalated_by'); //added
	 data.escalatedby = incescalby;
	 data.escalated = escalatedinc;
         var gdt = new GlideDateTime();
         gdt.setValue(incescaldate);
	 data.escalatedate = gdt.getLocalTime();	//added
	 }

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you. I had to modify this a little, and changed the assignment to 

gs.nowGlideDateTime();

Instead of gs.nowdatetime. Voila!