Skip to content
+1-888-319-3663

HELP ARTICLE

Unable to convert value to DateTimeOffset when running a Business Central Integration


The user has a SmartConnect.com map that used a Business Central Query using a filter on the query.


Because the filter should be dynamic – a user defined global variable, GBL_LASTDATEMODIFIED, was used and initially set as 2023-02-01.

Before Map Task to set the GBL_LASTDATEMODIFIED

var nd = new Date();
nd.setDate(nd.getDate() + parseInt(this.GBL_DELTA_DAY));  //GBL_DELTA_DAY is set to -1
this.GBL_LASTDATEMODIFIED = nd.toISOString().slice(0, 10);

return true;

 

The purpose of this script is to set the date restriction to the current day – 1, in other words, yesterday.

However when running the map or using the Data Source Preview, it fails with the error:


Unable to convert value to DateTimeOffset. CorrelationId: 9509xxxxxx

Because we get back a CorrelationId value, we know the error is coming from Business Central and not SmartConnect.com.
What we can’t tell is why we are getting the error.

After further testing including setting the value in the restriction to a hard coded 2021-02-01 vs the global variable used previously – we still received the same error.  The conversion issue wasn’t a code or global variable issue.

A bit more investigation gave us the solution – this custom field is actually defined as a DateTime in BC and not just a Date.  Because we gave it just the date portion of the expected datetime, apparently Business Central didn’t just accept this and so threw this appropriate error.

The solution was to adjust the code to return a proper datetime value instead of just the date as was done previously.

As we were looking for “yesterday” in our code and since we now include the time portion, that actually presents a different problem.  Do we want the time “now” to be yesterday at the same time?  Or at midnight?  It could be either – it depends on how you want to do it.  Both solutions are given in the code block below.

Corrected code for Map Task to set the GBL_LASTDATEMODIFIED

//Get yesterday’s date and set time to midnight by appending on the string for that midnight
var nd = new Date();
nd.setDate(nd.getDate() + parseInt(this.GBL_DELTA_DAY));
this.GBL_LASTDATEMODIFIED = nd.toISOString().slice(0, 10) + ‘T00:00:00.00Z’;
return true;

or

//get the current datetime and set to yesterday at the same time
var nd = new Date();
nd.setDate(nd.getDate() + parseInt(this.GBL_DELTA_DAY));
this.GBL_LASTDATEMODIFIED = nd.toISOString();
return true;

While this example was setting the field restriction for a datetime field on a Business Central query, I would expect this same type of error if we were to be sending a Date value to a DateTime field in Business Central.

RECENT POSTS


How to set up automatic payments on eOne's website portal
Downloading older versions of SmartConnect
SmartList Favorite Tracking SmartList Builder Template
SmartList Favorite Tracking History SmartList Builder Template
SmartList Builder GoTo opens to the wrong record

POPULAR POSTS


SSL Security error using OLEDB Connection
This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms
Removed Part: /xl/vbaProject.bin part. (Visual Basic for Applications (VBA))
The server process could not be started because the configured identity is incorrect.
Using WINSCP and a task to upload or download files from an SFTP site

CATEGORIES

TAGS

Business Central CRM D365 Business Central Dynamics 365 dynamics crm Dynamics GP Dynamics NAV Econnect Employee Spotlight eone eOne News error Error Message Events Excel Excel Report Builder Extender Flexicoder GP integration Map Microsoft dynamics crm Microsoft Dynamics GP Navigation List Builder Office Relationships Partner All Hands Call Popdock promotions release SalesForce SalesForce.com SmartConnect SmartConnect.com SmartConnect Bootcamp SmartConnect Maps SmartConnect Office Hours SmartList SmartList Builder SmartPost SmartView SQL Tech Tuesday Templates training Zendesk

Integrate & Automate without Any Code.

SmartList Data has Never Been Faster.

The Easiest Way to Report on GP Data.