Checking OnValidate

Here’s a seemingly simple question (and I’ve SEARCHed the forum and checked the manual, and tried some code): How can I check whether a field has successfully passed its default validation? Note that I am not asking whether there were any errors when executing the OnValidate code. I’m asking because I would like to send a MESSAGE when the user enters wrong data. Of course, I can always run some validation myself, but I’d like to know if I can piggy back onto the existing validation. Thanks, Alastair

Hi Alastair, I’ve been reading your posting several times - my head spins - and I’m still clueless… Pls. examplify or elaborate a bit. You want to (pre)validate before you actually validate or what? Oh, well - I guess I’m a bit dense.

Hi sv, sorry if I wasn’t clear and you spent a lot of time trying to decipher my posting. I’d like to emphasise that I am asking out of curiosity, as I have no problem finding a workaround in this case, but I think it would be useful to know the answer. Here’s a (hopefully clearer) explanation: I have a new table 50002 that links to the Dimension Value table. In 50002, users can enter more details about BUSINESS_UNITs (phone, fax, etc.), but if they want to create a new BUSINESS_UNIT they must go to the Dimension Value table. So in table 50002 (or in its form), I would like to put something like this in the Bus_unit_code OnValidate (or Bus_unit_code OnAfterValidate): IF errors-occurred-in-validation THEN MESSAGE('You can only select from existing business units. To create a new business unit, ’ + ‘go to GL, Setup, Dimensions, Dimensions, BUSINESS_UNIT, Dimension, Dimension Values.’); My problem is how to set errors-occurred-in-validation. I could do my own validation, e.g. IF NOT DimVal.GET(bus_unit_code) THEN … I thought that this should work: IF NOT bus_unit_code.VALIDATE THEN … but this would only run the code in OnValidate trigger – I want to run the default validation and check its outcome. Can this be done? I hope this is clearer. Alastair

Hm, why do you need to perform an explicit check for an existing business unit? If you have defined a table relation for the business unit field in 50002, the system will automatically show an error message if a non-existent business unit was entered. Is this just to print a more descriptive message in case of an error, so the user can immediately see where he is supposed to define the new unit? I was just as confused from your first post as sv [;)]. I think you are using the term “validation” for two different purposes here, for checking the validity of some data as well as for the “Navision meaning”, i.e. setting a field’s value and run some code afterwards. This probably causes some of the confusion…

quote:


Originally posted by xorph
Hm, why do you need to perform an explicit check for an existing business unit? If you have defined a table relation for the business unit field in 50002, the system will automatically show an error message if a non-existent business unit was entered. Is this just to print a more descriptive message in case of an error, so the user can immediately see where he is supposed to define the new unit?


Exactly.

quote:


I was just as confused from your first post as sv [;)].


My apologies to everyone who read the first post. [:I] Alastair

If the system detects that the user entered an illegal value (i.e. a value not found in the lookup table), it will throw an error and no more code will be executed. The OnValidate trigger will not help you either - its main purpose is not to ensure the validity of the data entered (this can be achieved with field properties just as well), but to cause side effects like calculating other fields’ values. So there is no “return value” or “success flag” of any kind. Once again, an error will prevent any additional code of yours from being executed. So I guess your best bet will be to put some code in the field’s OnLookup trigger and do all the validation (i.e. validity checking) as well as the actual field assignment entirely yourself.

Thanks Heinz, I thought it would be something like that. Regards, Alastair

If you simply want more control you can do something along these lines:IF DimVal.GET(bus_unit_code) THEN VALIDATE(bus_unit_code) ELSE MyErrorCode; Note:

  • The property ValidateTableRelation must be set to “No” otherwise you’ll get an internal Navision Error.
  • Use ERROR in stead of MESSAGE or you might end up with undesired data.
    Don’t know if this is of any help…

Yes, it is helpful. I have implemented this now. Thanks sv. Alastair