Hi I have to insert Sales records from a ASCII batch file into the Sales Headers and Sales Lines table. What I’d like to do is just fill in the fields, call VALIDATE on each filled-in field, and then, if all VALIDATEs succeed, I would INSERT the new Sales Headers / Sales Lines record. Since there is a lot of validations built in the various OnValidate triggers of the Sales tables, this seems like a good idea. Like this I could profit from the code written there. If the validation does not succeed for any reason, I’d like to print an error message AND CONTINUE TO THE NEXT RECORD in the ascii batch file. Now this nice plan doesn’t seem feasible, for the simple reason that it’s not possible to catch any Validation error. If an error occurs, Navision stops the entire program, and the rest of the ASCII batch file won’t be processed. Is there any possibility to circumvent this? Or do I have to write the entire validation code again??? [xx(]
You could write all your VALIDATE’s inside a codeunit. Then, from your original object (perhaps a Dataport) call the Codeunit and check for the return value: [OK] := CODEUNIT.RUN. If the codeunit returns true, all validation were succesful and you can insert the record. Else, something went wrong (but execution is not stopped) and you can write an error message.
Sorry, there is no TRY-CATCH mechanism as with some languages. (I would be very pleased to find that there is a way round this!) If you can spare a couple of tables for temporary storage , you could probably import the ascii file into the temporary table and process it bit by bit. One of the tables stores the ascii file data, the other table will be used as a form of log of whats happened. 1) The codeunit that runs through each of the records and inserts into sales headers/lines. Note that the codeunit is single instance, and is run on the navision timer. 2) Before processing the record, it writes an entry in the log effectively saying its about to try record x. 3) If no error occurs, then the codeunit writes a second entry into the log saying its completed processing record x. 4) If an error occurs, the codeunit exits without completion but because its on a timer, it will start off where it left off previously after a minute. The important thing to note is that before processing a record, it can check to see if it has started processing but not completed (no completion record). This indicates that there is potentially a problem with that record, to skip it and process the next record. This works best with NAS and is probably only worth the effort for a regular data import. Hope this makes sense, its been a long day so thinking is difficult! Regards, edd
Thanks Nelson, your Solution works very well. The only pity is that I cannot get hold of the actual error message - but I guess I’ll have to live with it. I however can’t understand why Navision makes it so hard for their users to do code reuse…
quote:
Originally posted by urs.eichmann
Thanks Nelson, your Solution works very well. The only pity is that I cannot get hold of the actual error message - but I guess I’ll have to live with it. I however can’t understand why Navision makes it so hard for their users to do code reuse…
Check out Table 36, the function SetHideValidationDialog and the variable HideValidationDialog. This is the “standard” way of avoiding errors and messages when reusing code. In stead of displaying (or ignoring) the errors you can create an errorlog where you put the errors.
But this only works if the original programmer supports it. This is only very rarely the case, e.g. in table 36 it is ok but in table 37 (Sales Line) it already is not done anymore. Since I need to add sales lines, it is of no use to me. But thanks anyway for your help
I recently saw a topic (dont know where mbsoline or mibuso) that discussed the “Navision Timer Control” automation or OCX. As i understood this library could do some sort of error catching. Search for navision timer and maybe you can find the topic.
quote:
[OK] := CODEUNIT.RUN
Quite a nice representation of an optional return value with the new forum tags… [8D]