Using the "NOT" statement

I am trying to understand some already existing code in the NF database. For example, I understand why to use the code “Customer.GET” but why would you use the code “If not customer.GET” ? What is the idea behind this, as I have seen this used for other things too.?

Actually this is pretty simple, if you call Customer.GET(‘10’); and this customer doesn’t exist, you will get an error. By using the IF statement, you can determine whether or not the function call suceeded. Take a look at the online help, as this has some examples of how to use. /Soren

Many functions in Navision, like GET or FIND a record, give a return value. This can be (in this case) a TRUE or FALSE as indicator the desired action was done successfull or not. You can just perform the action, but when the result is FALSE, you will get an error. But by making the action part of the IF THEN comparison, the result will be evaluated as true or false for the IF statement and the consequent action will be taken. John

So, if I am understanding this right, I code use the NOT statement in the following context ? If NOT Customer.Get then error ( The customer does not exist in the database);

quote:


Originally posted by Dean Axon: So, if I am understanding this right, I code use the NOT statement in the following context ? If NOT Customer.Get then error ( The customer does not exist in the database);


Actually you would normally not do it this way. The think is that if you don’t check the return value of the GET function and this value is false, then a runtime error will occur with the message “The customer x does not exist”. So if you just want to display such a message, then you don’t really need either the NOT statement or the ERROR functions. Just the Customer.GET; An example where it makes sense to use it:


  IF NOT TaxPostingSetup.GET("Tax Bus. Posting Gr. (Price)","Tax Prod. Posting Group") THEN
    TaxPostingSetup.INIT;

In this code (take from table 27 Item), the system is using the setup table later in the code (not displayed) and if you didn’t use the INIT on a newly defined record and was checking this, then you migh get another runtime error. Best regards, Erik P. Ernst, webmaster Navision Online User Group

The NOT statement can also be used to reverse a bolean // False to True or True to False Ship:=NOT Ship; IF Ship THEN Ship:=NOT Ship; David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk