---------------------------
Microsoft Dynamics NAV Development Environment
---------------------------
Assignment is not allowed for this variable.
---------------------------
OK
---------------------------
and if I try to do Message(FORMAT(dto.Offset.Hours)) I get
---------------------------
Microsoft Dynamics NAV Development Environment
---------------------------
The variable is not a record. 'Variable.Field' is invalid.
---------------------------
OK
---------------------------
ok, appearently TimeSpan is mapped to Duration, so if I replace ts type to Duration, assignement works fine, however Duration still comes up empty, even though in VS it works fine..
It's not possible using pure C/AL. NAV runtime intercepts any assignment of .NET variables, and immediately maps the type that directly maps to an NAV type. There is no way to prevent it, as long as you are using DotNet variables. You could write your own assembly that wraps the methods you need, and then you could call it.
To illustrate the depth of the problem, I can provide this code:
Assembly := Assembly.Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86');
o := Assembly.CreateInstance('System.TimeSpan');
arr := arr.CreateInstance(GETDOTNETTYPE(Type),1);
arr.SetValue(GETDOTNETTYPE(''),0);
m := Assembly.GetType.GetMethod('CreateInstance',arr);
arr := arr.CreateInstance(GETDOTNETTYPE(''),1);
arr.SetValue('System.TimeSpan',0);
o := m.Invoke(Assembly,arr);
MESSAGE('%1',o.GetType);
Obviously, I never handled System.TimeSpan directly, I used the most complicated reflection I could think of to create an instance of System.TimeSpan, but NAV runtime has still intercepted the output of the m.Invoke, which has indeed returned System.TimeSpan, and has converted it into Microsoft.Dynamics.Nav.Runtime.NavDuration immediately as it was returned from the method call.
So - unfortunately, nothing at the C/AL level that you can do. Sorry.
(Co-)author of "Implementing Microsoft Dynamics NAV 2009" http://vjeko.com/
hm.. could it be that dt.Now gets converted to NAV DateTime, before being passet to the constructor, and in process loses "Kind" property/information..?
Comments
but I cannot do this on NAV:
because on the line ts := dto.Offset I get
and if I try to do Message(FORMAT(dto.Offset.Hours)) I get
To illustrate the depth of the problem, I can provide this code:
Obviously, I never handled System.TimeSpan directly, I used the most complicated reflection I could think of to create an instance of System.TimeSpan, but NAV runtime has still intercepted the output of the m.Invoke, which has indeed returned System.TimeSpan, and has converted it into Microsoft.Dynamics.Nav.Runtime.NavDuration immediately as it was returned from the method call.
So - unfortunately, nothing at the C/AL level that you can do. Sorry.
http://vjeko.com/
however, do you have any clue as to why the returned duration is empty, instead of containing TZ offset?
http://vjeko.com/