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
   Can I Bind an Attachment to a Specific Activity in Infor CRM version 7.54?
Recently I had a user ask if they could bind an attachment to a specific Activity within Infor CRM??
Posted on Jul 07, 2015 by Dale Richter to Infor CRM Questions & Answers
 
   Infor CRM (Formerly Saleslogix) Iterating through all tabs on a Page
 Using the TabWorskpace you can iterate through all the tabs on a page and do something with them, l
Posted on Jun 19, 2015 by Kris Halsrud to Kris Halsrud's Blog
 
   Infor CRM (Formerly Saleslogix) Hiding Tabs at Runtime Without Using Modules
 As Ryan wrote a long time ago, you can create a module and add it to a page in the Infor CRM web cl
Posted on Jun 10, 2015 by Kris Halsrud to Kris Halsrud's Blog
 
   How I assign ownership to a group of Leads in Infor CRM?
There is a tool within Infor CRM to align Accounts to different Account Owners. It is called Territory Re
Posted on Jun 05, 2015 by Dale Richter to Infor CRM Questions & Answers
 
   Infor CRM (Formerly Saleslogix) Adding a Client Side Confirmation on a Dependency Lookup in the Web Client
 We recently had a client who wanted to have a user confirmation prompt before a user was allowed to
Posted on May 28, 2015 by Kris Halsrud to Kris Halsrud's Blog
 
Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2015 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