I’m trying to insert a ValidateWrite on CreditMax field in the registration form the client.
I’ve tried to leave the field as required and even tested the following lines in the code, however, for the existing entries, it works correctly, allowing not let the value of the credit limit as $ 0.00, but the new entries he is appearing error screen and leaves fill the field.
Does anyone have an idea how I can write this line and where (Form or Table) that are not entries with a credit limit = $ 0.00 allowed?
<i>boolean validatecreditmax()
{
boolean ret;
if (this.creditmax == 0)
throw error("Limite de Crédito Deve Ser Maior que R$ 0,00");
ret = super();
return ret;
}</i>
*or*
```
<i> if(!this.CreditMax)
{
throw error("Limite de Crédito Deve Ser Maior que R$ 0,00");
}</i>
```
```
```
```
Thanks,
```
```
```
```
Mateus Furrier
```
Friends, I have created the code in the table CustTable CreditMax field on the form, however, he did not forbid the user to leave the field with value 0.00.
When I compile, the following message appears:
Unreachable code.
Detail: failed leaving the code like this:
this.creditmax
needed change
CustTable.CreditMax
Sorry for my english and insistence on this point, but it is extremely important to our company.
Don’t write it in field’s validate() method - if a user keeps the default value, validate() won’t ever execute. You want to do the validation in validateWrite(). If the validation isn’t something specific to this one form, put it into validateWrite() on the table (i.e. not to the form data source).
See this example:
public boolean validateWrite()
{
boolean ok = super();
if (this.CreditMax == 0)
{
ok = checkFailed(...) && ok;
}
return ok;
}
Friends, I think the problem was in an applied customization.
The CreditMax field was taken to another form, however, referencing the CustTable table. As needed to click a button to open the screen credit, the error message appeared and did not leave open this canvas to fill with the value.
I put the field again in the form of CustTable. Thus, it is now working perfectly.