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
   Editing Filters in Saleslogix Web Client 8.0
Is it possible to add or remove Saleslogix filters from the List view in Accounts?
Posted on Apr 08, 2014 by SalesLogix Support to SalesLogix Questions & Answers
 
   Bug in the Saleslogix Web LiveGrid Lookup dialog
I recently ran into an issue with the Opportunity Products grid in the Saleslogix web client.  I cli
Posted on Apr 04, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Saleslogix Web Client Controls are Missing
Every so often we hear that a user can no longer add products to an opportunity whether it is a new oppor
Posted on Mar 24, 2014 by Mark Duthoy to SalesLogix Support
 
   Major Problem in Saleslogix v8.1 Cloud Instances
I have been working with a new client who is on the hosted cloud solution for Saleslogix version 8.1.&nbs
Posted on Mar 19, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Setting the Defaults on the Insert Account/Contact Duplicate Record View
When creating a new Account/Contact record in Saleslogix web, you have the ability to check for duplicat
Posted on Mar 10, 2014 by Jason Buss to Jason Buss' 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