AX – D365FO – Avoid saving record in a table

Imagine you want to avoid saving a record of a table if a particular condition is met.

You must access table and use ValidateWrite method

Only one record can have this checkbox set to TRUE.

If the use tries to set as TRUE another record the record cannot be saved.

We will use the ValidateWrite method of the table in order to extend the logic globally, but if you want to use the logic only on a form you can use the ValidateWrite () on the Form DataSource

So use this code

public boolean validateWrite()

{

   boolean ret;


   //Prevent from saving if DefaultRule is already valorized

   ERAWriteOffRule eraWriteOffRule;

   ret = super();

 
   //Prevent from saving if DefaultRule is already valorized

   select eraWriteOffRule

   where eraWriteOffRule.DefaultRule == true;

 
   if(eraWriteOffRule && eraWriteOffRule.RecId != this.RecId)

   {
       ret = checkFailed("@$AB164");
   }

   return ret;

}

This is the result

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...