Options

How to make a field mandatory...newbie question

powerbouwerpowerbouwer Member Posts: 3
edited 2003-04-07 in Navision Attain
Hi,

I'm quite new with Navision so please don't shoot me :-)

I want a field in a table to be mandatory (let's say 'Email Adress'). Also when creating a new record in that table through a form and the user forgets to fill in the 'Email Address' and wants to enter another new record or closes the form I want to inform the user that the Email Address should be filled in, but without (this is very important!) losing all the other entries in the new records!

So, to summarize this : what's the best solution to be sure a field is filled in a record and what trigger(s) do I need to code and where (Table/Form) ???

Thank you very much!

Wim Teuwens

Comments

  • Options
    navnavnavnav Member Posts: 16
    Try out the NotBlank property for a field in a table.
    Try using TESTFIELD in code.
  • Options
    SbhatSbhat Member Posts: 301
    Hi,

    As such there is no way make a field mandatory in Navision. Yes, you could put some code in onclose trigger of a form but that would give you hell a lot of problem. The only way to check for mandatory value in a field is while posting. Whenever you post check for the value in the table and flag a error message.

    Thanks

    Best regards
    Suresh
    email : sbhatbng@hotmail.com
  • Options
    navnavnavnav Member Posts: 16
    Also check the delayedinsert property.
  • Options
    Theunis_ModdermanTheunis_Modderman Member Posts: 9
    In the end, it will appear that it is not possible to make a field mandatory. For example: The OnClose trigger is not activated if yoy scroll the records, but only if you close the form. So also this is not a proper solution.

    In most cases however the customer needs only few fields to be absuolutely mandatory. If that is the case, we use the following solution:

    At insert, automatically set de value for Blocked = Yes (You could use the InitValue property for this, or add a line to the OnInsert-trigger). The user normally needs to unblock the record before het can use it somewhere else in the application. In the OnValidate trigger of the field Blocked you test whether the fields that you consider to be mandatory are filled by the user. If not create an error. Of course you only perform the test if the user unblocks the record (not if he blocks it). For example:

    Blocked - OnValidate

    IF NOT Blocked THEN BEGIN
    TESTFIELD("E-Mail");
    TESTFIELD(Address);
    END;
    Theunis Modderman
    DSA Global Solutions bv
    Hoofddorp- The Netherlands

    t. +31 - 23 737 0 484
    m. http://www.dsa-gs.nl
  • Options
    WaldoWaldo Member Posts: 3,412
    What about the following method:
    On Table Level:
      - use "not blank"-property for the mandatory field - add following code
    OnInsert()
    TESTFIELD(Mandatoryfield);
    

    On Form level:
      - Work with "Delayed insert"

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
  • Options
    Theunis_ModdermanTheunis_Modderman Member Posts: 9
    This is also a possibility. However, there is on big disadvantage to this method (which I think is unacceptable): if the end-user forgets to fill the mandatory fields, not only an error will be generated, but also all the data he has entered correctly in the other fields of the record will be gone.

    Maybe you think this will work educational, but most users will hate you for building such a solution!
    Theunis Modderman
    DSA Global Solutions bv
    Hoofddorp- The Netherlands

    t. +31 - 23 737 0 484
    m. http://www.dsa-gs.nl
  • Options
    powerbouwerpowerbouwer Member Posts: 3
    Hi all,

    Thanks for the replies...

    What strikes me the most is that (what to me seems basic development) there seems not to be a one-go solution for this problem. Indeed my biggest problem is that all the fields will be blanked out when there's an error on the form (ex. field not filled in). And yes my customers WILL shoot me :-)

    Anyway, I'll try out the suggestions from you guys and hope for the best.

    Thanks again.
  • Options
    DenSterDenSter Member Posts: 8,304
    I don't understand, there is a very simple way to do this. Granted, Navision is by no means a sophisticated development environment like Visual Studio, but it gets the job done in no time.

    Set your form's DelayedInsert property to YES, like was suggested. Then put the validation code in your table, not the form, that way the form won't close if there is an ERROR. In both the OnInsert trigger and the OnModify trigger, you do the TESTFIELD, like suggested. You will not be able to insert or modify the record without having a value in your field, and all the other values will be preserved. I use it all the time.

    HTH
Sign In or Register to comment.