How to update a record and canceling the submit of the form?

How to update a record and canceling the submit of the form?

Hello,

I am trying to update a record with the data introduced in a form, but I dont want to create a new entry in te report, only update the entry that exists. 

I tried checking if the entry exists with On Validate, but if I use "cancel submit", the entry does not update. Although if I delete "cancel submit", the entry updates but a new entry with the form data appears, and that is the thing I dont want. 

Is there a way to do this? This is my simple code

  1. if (Equipo_Comercial[SalespersonID != input.SalespersonID].count()  >  0)
  2. {
  3. actualizar = Equipo_Comercial[SalespersonID == input.SalespersonID];
  4. actualizar.Nombre = "Test"; 
  5.         alert "Actualizado";
  6. cancel submit;
  7. }