Field Validation

When the user leaves a decimal field on the form, I need to check that the field does not equal to 0(default value). HOw can I do this? The OnValidate trigger does not fire if the user does not change the value in the field. I tried using the OnModify trigger for the table. The field that I am checking is one of the last on a tabular subform. So as soon as some other field before the required field is modified the OnModify trigger fires and the error message pops up. This happens even before the user has had a chance to get to the required field. I tried adding the test code to the OnBeforePutRecord trigger of the form. As soon as the error messae pops up the form closes instead of focussing on the feld. The field is on a subform(tabular). Please help. Pari.

Search the forum for “mandatory”.

Pari Set the NotBlank property to Yes on the field. 1. If part of a primary key the record will not be saved until a value is entered. 2. Not part of primary key the validation will not be run until the field is validated. Option 2 Form TextBox OnAfterValidate trigger TESTFIELD(“My Field Name”); This will Error if blank or Zero. David Cox email: david@mindsource.co.uk

David: I tried settng NotBlank property of the field to Yes. I then added the code TESTFIELD(“Nominal Thickness”); to the OnAfterValidate trigger of the field “Nominal Thickness”. It does not work. I think the trigger fires only if the OnValidate trigger fires. The problem is my field’s default value is 0 and it is not part of the primary key. When the user just hits tab on the field instead of entering a value(prefers to leave it as default value 0) the error message should pop up. Unless the value is changed, the OnValdate trigger does not fire. I think having a trigger OnLeave for a TextBox on the form will help. Thanks. Pari.

Unfortunatly you will have to put the code on the form This is pretty straight forward, but you need to allow for a lot of conditions, such as mouse vs tab on the field etc. The place to start is:


**OnDeactivate()**
message('deactivate');

the prolam is that if you put an error message, then you will loose all the data entered on the form. A better solution is to find a simpler way of indicating to the user that the field has not been entered yet. Try this for instance:


**OnFormat(VAR Text : Text[260];)**
if "my value" = 0 then begin
  text := '<You must enter a value>';
  CurrForm."My Value".UPDATEFORECOLOR(255);
end;

It works quite well. good luck _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

Check if the form (tablebox control) is having the property DelayedInsert = Yes. Then the insert/modify triggers are not fired before you actually leave the line and that gives you the chance to check the fieldvalue at the right time. John

If you notice, Navision doesn’t do much (if any) validation when data is entered. They do it at Posting Time. This might be because they made it near impossible to check at data entry. :slight_smile: Is it possible to check if your field has been entered during a posting routine? That would be the simplest solution. David’s solution also requires code when you close the form and when you go to a new record. Another approach is to use the DelayedInsert on the Form and put code on the OnInsert trigger. This allows control of the entire record before it is inserted in the table. There are issues here with sub-tables requiring the key before, but if you have a simple table, this might be a much easier solution. In summary, neither method is what I would call an ideal solution, you just need to find the work-around that fits your circumstances the best. Chris Krantz NCSD,NCSQL,MCSD,MCSE Microforum Inc. Toronto, Ontario, Canada

Basically what we are normally trying to do here is use C/Side to train users. It is not so much an issue of what trigger when, the thing is to get a solution to the problem. After many many implementations where this has been an issue, I have found that the best solution is a combination of 2 things. 1/ Give the user a clear indication of a potential error. 2/ Once the user has had a chance, then take an action to prevent an error in the database. looking at these individually:
1- If there are a few fields involved, eg one or two, then just highlight the field so the user can see where the value is missing.

  • If there are many fields, then place a function in the table that returns true if all fields are within tolerance, and add a red light green light indicator on the form in an obvious location.
    2- It is possible to put a function to generate an error when the form closes if fields are not filled. I do not like this, it only makes users hate you
  • The better solution is to check the fields when you need them, eg, when that item is used to populate another table.
    _________________________ David Singleton Navision Consultant since 1991 dmks22@home.com___________

A word of warning on the delayed insert option: If you decide to use the ERROR statement, it will roll back ALL OF THE FIELDS VALUES. This is usually not desireable. You could use the MESSAGE statement but, it still doesn’t assure the field being filled in. The moral to the story (as you have probably figured out) is that this is a recurring problem in Navision. I keep hoping that Navision will create a special trigger that checks not blank or not 0 properties even if the user changes nothing. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117

quote:


Originally posted by wbenefiel: A word of warning on the delayed insert option: If you decide to use the ERROR statement, it will roll back ALL OF THE FIELDS VALUES. This is usually not desireable. You could use the MESSAGE statement but, it still doesn’t assure the field being filled in. The moral to the story (as you have probably figured out) is that this is a recurring problem in Navision. I keep hoping that Navision will create a special trigger that checks not blank or not 0 properties even if the user changes nothing. Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117


I agree with you. I wish Navision would add a trigger. Pari.

Pari Is the Nominal Thickness the last field to be Input? If it is, could you not change the flow so one of the fields they know they have to fill in is the last then you can TestField from the other field! I.E. Quantity OnValidate() Testfield(“Nominal thickness”); David Cox email: david@mindsource.co.uk

quote:


Originally posted by David Cox: Pari Is the Nominal Thickness the last field to be Input? If it is, could you not change the flow so one of the fields they know they have to fill in is the last then you can TestField from the other field! I.E. Quantity OnValidate() Testfield(“Nominal thickness”); David Cox email: david@mindsource.co.uk


It is the last field; moreover I have the code currForm.UPDATE in one of the fields before Nominal Thickness. I need it because depending upon the value in that field I need to do some calculations and display the result on the screen. I cannot do currForm.UPDATE(FALSE) because the calculations are done in such a way that the fields in the table have to be updated. Pari.

quote:


Originally posted by David Cox: Pari Is the Nominal Thickness the last field to be Input? If it is, could you not change the flow so one of the fields they know they have to fill in is the last then you can TestField from the other field! I.E. Quantity OnValidate() Testfield(“Nominal thickness”); David Cox email: david@mindsource.co.uk


Yes. It is the last field; moreover I have the code currForm.UPDATE in one of the fields before Nominal Thickness. I need it because depending upon the value in that field I need to do some calculations and display the result on the screen. I cannot do currForm.UPDATE(FALSE) because the calculations are done in such a way that the fields in the table have to be updated. Pari.