TESTFIELD failure

vaprogvaprog Member Posts: 1,140
edited 2014-10-17 in NAV Three Tier
I'm in the process of porting some code from NAV 2009 R2 to NAV 2013 R2. The following line of code worked in 2009, but trows a peculiar error on 2013 R2:
WITH ParameterSpec DO BEGIN
...
  TESTFIELD("Parameter Type","Parameter Type"::Integer);
Microsoft Dynamics NAV

Break On Error Message:

Parameter Type must be equal to 'Integer' in Parameter Spec.: Code=TEST2, Line No.=10000. Current value is 'Integer'.
OK
Definition of field Parameter Type:
{ 12  ;   ;Parameter Type      ;Option        ;OptionString=[ ,Integer,Decimal,Code,Text,Date,DateFormula,TableFilter,Boolean] }
The debugger says, the value is Integer just before the error is thrown.

Has anybody any clue as to what might be wrong?

Answers

  • SavatageSavatage Member Posts: 7,142
    see the bottom example here:
    http://msdn.microsoft.com/en-us/library/dd301274.aspx

    Seems to be what you are experiencing.
    What are you trying to do with code?
    Only process something that has an integer parameter?
  • PrebenRasmussenPrebenRasmussen Member Posts: 137
    Either you have an error with a local variable named like a global variable, a local variable named "Parameter Type", or the debugger is messing with you (as so often before...).

    This code will work for sure - always!:
    SomeTable.OptionField := SomeTable.OptionField::Integer;
    SomeTable.TESTFIELD(OptionField, SomeTable.OptionField::Integer);
    

    1 Go through local/global variables.
    2 Skip the WITH ParameterSpec DO BEGIN line and add the tablevariable where neccessary.
    3 Insert a line like:
    IF CONFIRM('%1', TRUE, FORMAT(ParameterSpec."Parameter Type", 0, '<Text>')) THEN
    
    just before the TESTFIELD line.
    4 Try to isolate the problem in a new simple table with just a few fields of the appropriate type.
  • vaprogvaprog Member Posts: 1,140
    Thanks for your suggestions.

    I first added the record var explicitly in the code (but left the WITH in place. It must have no effect on that changed line of code, though
    ParameterSpec.TESTFIELD("Parameter Type",ParameterSpec."Parameter Type"::Integer);
    
    This did not help.
    I then added a
    IF ParameterSpec."Parameter Type" <> ParameterSpec."Parameter Type"::Integer THEN
    
    just in front of the TESTFIELD, which also did not bring about any change, which really made me wonder.

    I then noticed the field "Parameter Type" is a FlowField of Lookup type (CALCFIELDS was executed on it). However, the OptionSting value of the two fields differed. So, apparently, :bug: NAV used the OptionString definition of the table looked up from to show the value in the debugger and for the field value in the error message. The option constant, though was taken from the FlowField itself :roll:.
Sign In or Register to comment.