Tech Tuesday: Working with Date and Time Fields in Integration between Microsoft Dynamics CRM and Microsoft Dynamics GP using SmartConnect
Today’s Tech Tuesday article comes right from the trenches of working in the world of integration. In this article we are going to focus on date fields from Microsoft Dynamics CRM.
Oftentimes when customers need to transform date fields from one format to another they will just use the standard SmartConnect Date Calculation (under Additional Fields in the mapping).This will normally allow you to transform a date field from any format to any format. In the case of this specific customer we ran into two unique issues.
1) The first hurdle was that sometimes the date field coming from Microsoft Dynamics CRM would be NULL. This presents challenges as you have to make assumptions on how you handle NULLS.
2) The second challenge was that we had multiple regions involved. In this specific example, we had Microsoft Dynamics CRM Online (hosted in a US locale) and Microsoft Dynamics GP on premise in the UK.
This customer had a Dynamics GP field that needed that date value along with another Extender window that needed the date value. What we were able to do to accomplish this task was to provide a calculated field to meet the criteria for both scenarios. Here is the calculated field that was used below in VB.NET form:
‘Use the date field from your CRM Entity below
Dim dateString as string = _CUSTOMENTITY_STARTDATE
Dim provider as System.Globalization.CultureInfo = System.Globalization.CultureInfo.InvariantCulture
‘substitute the “en-US” below with the locale of the source data
Provider = New System.Globalization.CultureInfo(“en-US”)
‘Handle NULL/Blank value of date/datetime field
‘Convert the datestring provided to a date field in locale, then convert to desired locale
In this script we are using an interesting .NET feature. The CultureInfo class allows us to determine the locale of the date format. This in turn can be used to convert the dateString from Microsoft Dynamics CRM to the format of any locale. In our specific example we converted a US format date into the format that most of the world uses (in this specific instance, the UK). Additionally, we simply indicated that a blank value would return a standard date in the format that Microsoft Dynamics GP likes.
This script could be used to change any date/datetime field into a format suitable for Microsoft Dynamics CRM or Microsoft Dynamics GP.
Hope this helps you with any date calculation issues you may be trying to solve.
Chris DewWant more information on SmartConnect and the features it offers? Please contact firstname.lastname@example.org for more information!