Options

Error in Navision 360 fieldref

MarkWMarkW Member Posts: 6
edited 2008-04-01 in NAV Tips & Tricks
I have discovered an error when using fieldref’s in a 360 database. Observe the following code:

l_RecordRef.OPEN(DATABASE::TestCountry);

l_RecordRef.INIT;
l_FieldRef := l_RecordRef.FIELD(1);
l_FieldRef.VALUE := 'dk';
l_FieldRef := l_RecordRef.FIELD(2);
l_FieldRef.VALUE := 'Denmark';
l_RecordRef.INSERT;

l_RecordRef.INIT;
l_FieldRef := l_RecordRef.FIELD(1);
l_CodeVar := 'uk';
l_FieldRef.VALUE := l_CodeVar;
l_FieldRef := l_RecordRef.FIELD(2);
l_FieldRef.VALUE := 'United Kingdom';
l_RecordRef.INSERT;

The table “TestCountry” consists of 2 fields, field1 is a “Code 10” and field 2 is a “Text 30”.

When the first insert occurs, then value inserted in the “Code 10” field should have been “dk” but only “k” is inserted. The “d” is somehow removed, which leaves us with incorrect data. Furthermore, a lowercase value has now been inserted in a “code” field causing a “database structure error 1204 in module 19” (Corrupted data). When executing the code, no runtime errors occurs, you have to run a database test, or a backup, to see the error.

If you on the other hand take a look at the 2nd insert, the lowercase value “uk” is assigned to a local variable of the type “Code 10”, the “uk” is therefore changed to “UK” so no errors occurs here.

I can only produce this error in a 3.60 database, but a word of warning: Creating this code in a 3.70 database and importing the object in a 3.60 database causes the same error, even thou the code works fine in a 3.70 database, where the error seams to have been corrected.

Hope some of you can use this…

Regards
Mark Westergaard

Comments

  • Options
    krikikriki Member, Moderator Posts: 9,096
    There is another bug in 3.60 with recordreferences:
    when you assign a decimal to a decimal fieldreference, it is always truncated to 4 decimals.

    Best way to avoid both: do a client upgrade.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    MarkWMarkW Member Posts: 6
    Hi Kriki

    I tried assigning a text directly to a decimal field, this also causes a database structure error. Spooky that no runtime errors occurs here.
  • Options
    kinekine Member Posts: 12,562
    It is not recommanded to use RecordRef and FieldRef on NAV 3.60. First stable version is 3.70B or 4.00+.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    jlandeenjlandeen Member Posts: 524
    whew....this last point helped. I thought I was losing my mind! Code I tested in a 3.70B database was working fine but when the objects were imported into a 3.60 DB they were causing unhandled exceptions (i.e. my visual studio debugger tried to trap them).

    It's always fun to go back to older DB versions :?
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
Sign In or Register to comment.