Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

The value can't be evaluated into type Time.

Posted on by 670
So, I have a datetime column called [Starting Time] in an SQL Server Dynamics NAV (On-Prem) database. It appears to have a default value of '1753-01-01 00:00:00.000'. If a time is assigned to the field in Business Central the date part in the database advances one year (e.g.) '1754-01-01 15:07:27.007'
I've created an AL Extension in VS Code containing an API Page in which one of the fields defined is the aforementioned [Starting Time] (see below):
field(StartingTime; "Starting Time") { }
When I hover the mouse cursor over this field in VS Code it reports: '(field) "Starting Time": Time'
I've then downloaded the XML metadata from Dynamics NAV (see section below). Notice, it has defined the field as "Edm.String" ?
<Property Name=""StartingTime"" Type=""Edm.String"">
  <Annotation Term=""NAV.LabelId"" String=""StartingTime"" />
  <Annotation Term=""NAV.NavType"">
    <EnumMember>NAV.NavType/String</EnumMember>
  </Annotation>
</Property>
I've then create an OData connected service in a C# .NET Core 2.2 Web App in Visual Studio 2019.
See auto-generated code below:-
/// <summary>
/// There are no comments for Property StartingTime in the schema.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.6.0")]
public string StartingTime
{
    get
    {
        return this._StartingTime;
    }
    set
    {
        this.OnStartingTimeChanging(value);
        this._StartingTime = value;
        this.OnStartingTimeChanged();
    }
}
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.OData.Client.Design.T4", "2.6.0")]
private string _StartingTime;
partial void OnStartingTimeChanging(string value);
partial void OnStartingTimeChanged();
I have a Razor View as below, which displays a nice TimePicker control:-
@Html.EditorFor(model => Model.ServiceHeader.StartingTime, new { htmlAttributes = new { @class = "form-control", @type = "time" } })
The value chosen is returned to the Controller (e.g.) "01:00".
I populate the relevant object's properties and call the functions below to update the database via the OData interface:-
_context.AttachTo("API_Service_Header", lobjSH, "*");
_context.UpdateObject(lobjSH);
await _context.SaveChangesAsync(SaveChangesOptions.None);
... And I get the following error:-
{"error":{"code":"Application_EvaluateException","message":"The value \"1754-01-01 01:00:00\" can't be evaluated into type Time."}}
By the way I've tried formatting the value as just a time (e.g.) "01:00" and I've tried formatting it as full date (e.g.) "1754-01-01 01:00:00" - Same error.
Any help would be greatly appreciated?
  • Suggested answer
    keoma Profile Picture
    keoma 32,675 on at
    RE: The value can't be evaluated into type Time.

    edm.string seems to be wrong, should be edm.timeofday.

    set a valid time value in that field and try again.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans