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
   Change the Appearance of a Saleslogix (Now Infor CRM) Read Only TextBox Web Control
In the Salelogix web client, a read only control has a css style applied to it to make the background app
Posted on Oct 24, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Saleslogix (now Infor CRM) Web Client- Changing Label Appearances on Quick Forms
 I wrote previously about setting a label's appearance on a quick form using server side code.&n
Posted on Oct 02, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Error Attempting to Save an Entity: "E_FAIL(0x80004005)" in the Infor CRM (Saleslogix) Web Client
We recently had a client that was running into an issue when attempting to create one particular entity i
Posted on Sep 30, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Video: Demystifying Infor CRM (Saleslogix) Updates
Watch it now! If you missed yesterdays demo, "Demystifying Infor CRM (Saleslogix) Updates" ,
Posted on Sep 26, 2014 by Brianna Ojard to The Inbox
 
   Official Infor CRM Acquisition FAQ
What to expect now that Saleslogix is Infor CRM. Like many of you, it will take some time (probably a
Posted on Sep 18, 2014 by Brianna Ojard to The Inbox
 
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