Login / Register  search  syndication  about

          Kris Halsrud's Blog

Kris Halsrud on development and Integration with CRM and Development

Working with dates in the SalesLogix Web Client

The SalesLogix database stores most dates in the database in UTC time.  In the SalesLogix web client, the SalesLogix date controls automatically handle converting a bound date time to the local web client's time zone from the UTC equivalent.  The same is not true when retrieving dates and using them on other controls, like labels.  Let's take a look at some of the ways we can work with date time values in the SalesLogix web client:

Lets say we have a date time of 6/18/2012 11:00AM central time with a UTC equivalent of 6/18/20012 4:00PM.

Lets us also assume the web server is in central time and the client computer running the SalesLogix Web Client is in the eastern time zone.

DateTime utcDate= new DateTime(2012, 6, 18, 16, 00, 00);

Option 1- Direct binding of a text box with a date time:

txtBox.Text = utcDate.ToString();

This will return the date time with no conversion.  6/18/20012 4:00PM.

Option 2-  Binding a text box control using server time:

Sage.Platform.TimeZones tzs = new Sage.Platform.TimeZones();
Sage.Platform.TimeZone tz = tzs.CurrentTimeZone;
DateTime? x = tz.UTCDateTimeToLocalTime(utcDate);
txtBox.Text = x.Value.ToString();

This will return the date time in the server's local time zone since this server side code is running on the web server.  6/18/20012 11:00AM.

In order to return the local time equivalent (Eastern Time Zone) we need to switch from server side conversion to client side conversion.  We can do this as option 3.

Option 3-  Binding a text box control using client side time:

txtBox.Text = utcDate.ToString();

//Client side script to show local client time based on UTC conversion using JS date function toLocaleString
string clientscript = string.Empty;
clientscript = "var sdt = document.getElementById('" + txtBox.ClientID + "').value + ' UTC';";
clientscript += "var d = new Date(sdt);";
clientscript += "var lbl = document.getElementById('" + txtBox2.ClientID + "');";
//clientscript += "lbl.value = d.toLocaleString();"; //Returns full date formatted differently then other dates so following formats date equally
clientscript += "lcldt = new Date(d.toLocaleString());";
clientscript += "var formattedDT = lcldt.getMonth() + '/' + lcldt.getDate() + '/' + lcldt.getFullYear() + ' ' ;";
clientscript += "var Hours = lcldt.getHours(); var PM = false;";
clientscript += "if (Hours>12) {PM=true; Hours = Hours -12;}";
clientscript += "formattedDT = formattedDT + Hours + ':' + lcldt.getMinutes() + ':' + lcldt.getSeconds();";
clientscript += "if(PM) formattedDT = formattedDT + ' PM'; else formattedDT = formattedDT + ' AM';";           
clientscript += "lbl.value = formattedDT;";
ScriptManager.RegisterStartupScript(Page, GetType(), "UniqueInjectedScriptName", clientscript, true); 

Here in this sample we are doing a server side binding of a text box, with no conversion.  The time would show as 6/18/20012 4:00PM.  However, we are also then injecting java script onto the form that examines the bound text box control, gets the date value and then using the Java script's Date.toLocaleString function converting the UTC equivalent to the browser's local time.  We then set the text box back to display that time which will be 6/18/20012 12:00PM.

So there you have it, three scenarios to work with dates in the SalesLogix web client.  Of course the SalesLogix date control already does all of this for you with the server side a client side libraries associated with the control OOTB.

What's This?
  
Bookmark and Share

About Kris Halsrud

   Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.


Related Content
   Easily Showing and Hiding Tabs at Runtime in Infor CRM (Saleslogix)
Showing and hiding tabs in the Infor CRM (Saleslogix) client should be an easy thing. It should be someth
Posted on Dec 16, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Problem setting SLXTextbox enabled property / Setting unexposed base control properties for a custom control
I recently had an issue with a Quickform where I was attempting to set the Enabled property of a TextBox
Posted on Dec 05, 2014 by Jason Buss to Jason Buss' Blog
 
   Checking Infor CRM (Saleslogix) Picklists for valid data
This week I received a question about a particular picklist. One of the picklist items, when chosen, wou
Posted on Dec 05, 2014 by Dale Richter to Infor CRM Questions & Answers
 
   Avoiding the Dirty Data Message When Programatically Redirecting to a Record in Infor CRM (Saleslogix)
In my last post I wrote about using the OnClientClick property of a control (or button) to run JavaScript
Posted on Dec 02, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Infor CRM (formerly Saleslogix) Web- Dependency Lookup OnChange Event Not Working Correctly
In the Saleslogix 8.1 web client the dependency lookup still has a problem with the OnChange event. 
Posted on Nov 26, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register