Codeunit validation error

Hello,

Im programing with navision classic for about 2 months and i came across an error in my codeunit, i have one table with some values and the other the problem is that my second table has an onvalidate trigger and lets say when im trying to secondtablerecord.VALIDATE(second_table_field,first_table_field); i get an error that says that the value doesnt exist in the second table i somehow need to intercept the error and lets say make waserror:=TRUE variable is it possible and how is it done in a single codeunit? and my codeunit funcion is in a cycle NEXT so i need it not to break it on error can you help me? :slight_smile:

Welcome to DUG

Can you explain the scenario?

May be we can suggest different solution?

the scenario is this i have a table with data and i need to transfer it to another table i use this kinda code:

Variables:

Name,Data type,sub type,length

FRec Record First_table
SRec Record Second_table
WasError Boolean

Functions:

TransferFromTo()

OnRun FUNCTION CODE:

TransferFromTo;

FUNCTION TransferFromTo CODE:

FRec.SETRANGE(“Processed”,FALSE);
FRec.FIND(’-’);
REPEAT

WasError:=False;
SRec.INIT;
SRec.“No.”:=’’; //THIS IS NEEDED SO THAT IT CAN GENERATE A NEW NUMBER SEQUENCE
SRec.INSERT(TRUE); // TRUE Because oninsert triger has a new number generation sequence code

SRec.VALIDATE(FRec.field_name,SRec.field_name); // I GET AN ERROR HERE

SRec.MODIFY;

UNTIL FRec.NEXT = 0;

//----------------------------------------------------------------//

What i need is to intercept that error lets say like an IF statement if it is successful than do nothing but if it fails and gives me ant erro set the WasError:=True;
the data types match of both fields length matches , the Frec.field_name is a normal field which has a table relation to another table where all the possible values it can get are stored but when i try to insert a value that doesn’t exist in there i get the error: third_table_name CODE value_that_i_try_to_insert does not exist editing the table on validate code is not an option so i need a simple way to intercept the error. Thank you in advance . :slight_smile:

Hi Tomas,

try this:

instead of this: FRec.FIND(’-’);

use IF FRec.FIND(’-’) THEN BEGIN

// rest of your code here

END;

SRec.VALIDATE(FRec.field_name,SRec.field_name);

should be

SRec.VALIDATE(SRec.field_name,FRec.field_name);

In Order set error…

you can do setrange with 3rd table with FRec.field_name before validating and if record found then you can validate with SRec.field_name

or simply set error…

JSP,

i could use this but it will find the records because in Frec table they are all there, so that doesn’t help me :slight_smile:

Mohana ,

i wrote the validate syntax exactly as you said your solutions helps me but as i have about 30 validation syntaxes i have to write the get syntaxes to all of them in case of an error isint there some other way ? :slight_smile: if there isint this i think will suffice

is there a way to lets say if an error accours not to break the cycle but to continue and at the end get the original NAV error code?

I think you need to define parameter for Second record for it will be not generate any data or empty. try to use SETRANGE before Looping with First Record and define its relation i think this should work, if both record avaiable

the main idea is to getlasterrortext o that means i have to go through all the code and if i get an erro insert it to a LOG lets say i have a name test and a table where the names are stored the third table Names which has 3 entrys test1,test2,test3 so if i use validate the NAV will give me a error because name test doesnt exist in the NAMES table that means i have to somehow not to stop the process and at the end of the code insert the getlasterrortext string to a log.

Okay I think i get your point, perhaps try to put some checking in Looping before INIT and generate an error message within the checking statement, like your conditions “doesnt exist in the NAMES”

ok i found the sollution to this problem it was a bit tricky but it goes something like this:

OnRun()

IF Trigger=’’ THEN BEGIN

RUNMAINFUNCTION;
END;
IF trigger=‘runit’
BEGIN
RunValidationFunction(Record)
END;

RUNMAINFUNCTION()
FRec.RESET;
SETRANGE(FRec.Field,Value);

IF FRec.FINDSET THEN
REPEAT
//here you need one function to pass a record and a triger value lets say SetTriger(‘runit’,Srec);
boolvar:=CODEUNITVariable.RUN;
IF boolvar THEN
BEGIN
//write if everythings is fine
end ELSE
BEGIN
//do something if its bad
END;

UNTIL Frec.Next=0;

but still thanks for trying to help me maybe this sollutionds will be helpfull to someone :slight_smile: