Validate field CustTable

Hello everybody!

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
```

Hi,

Try writing in the form > ds >field > validate method…

<i>boolean ret;

    if (this.creditmax == 0)
       ret = checkfailed("Limite de Crédito Deve Ser Maior que R$ 0,00");
else
    ret = super();

    return ret;</i>

*try it once..*

Friend, when I create the method in the field, the following message appears when compiling

CustTable Super() not allowed here

Hugs

Hi Try this code

<i>boolean validatecreditmax()
{

    boolean ret;</i>
 *;*
 *ret = super();*
<i>

    if (this.creditmax == 0)</i>
<i>   {
       throw error("Limite de Crédito Deve Ser Maior que R$ 0,00");</i>
 *ret = false;*
 *}*
*else*
*{*
 *ret = true;*
<i>}

    

    return ret;
}</i>

Hi Try this code

<i>boolean validatecreditmax()
{

    boolean ret;</i>
 *;*
 *if (this.creditmax == 0)*
<i>   {
       throw error("Limite de Crédito Deve Ser Maior que R$ 0,00");</i>
 *ret = false;*
 *}*
*else*
*{*
 *ret = true;*
<i>}
    </i>*ret = super();*<i>
    return ret;
}</i>

super should not be used, unless it is an override method.

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.

hugs

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;
}

Friend Martin Dráb, Thank you also.

If I put in validatewrite, he does not let me fill in the field, because the error is displayed continuously.

Initially I had the inserted there, along with other pre-existing validations.

In the case of existing registers, it worked perfectly, leaving the value is zero, but for new registrations, no.

To enter the value, the user clicks a button and it opens another form to enter this value. It is our CustCredit form

validateWrite() is normally called when a record is being saved and what I described is the usual pattern used across the whole AX.

What in your code calls validateWrite() continuously?

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.

Thank you all!