I have been trying to get my C# program to insert records directly into a Dynamics AX 2009 database using the .NET business connector.
So far I can easly insert a string, int, int64, enum (NoYes), but it fails every time I try and insert a dateTime field (in AX the field is defined as UtcDateTime) with the error:
The supplied method arguments are not valid.
I’m sure this is something simple that I am just missing.
Snippet of code:
using (axRecord = ax.CreateAxaptaRecord("TempTable"))
{
// Fails on this line with error: The supplied method arguments are not valid.
axRecord.set_Field("DateField", DateTime.Now);
axRecord.Insert();
}
I have tried passing through as a string and using a dateTime.parseExact, etc., but it still does not seem to work.
It should work.
I made a static helper class and included it in my project:
Then I could pass in values like this:
Now this solution assumes Norwegian culture throughout the system.
The value “record” is of type AxaptaRecord.
StartDate is a field that extends (eventually) TransDate.
I don’t see why this shouldn’t work for you.
Here’s some other tips:
Look for errors in the Event Viewer
Look for spelling errors in you
variable contained in strings (like
“StartDate” in my example).
Visual Studio and your x++ code.
🙂