Search code examples
genexus

how to add a record in a sub-level transaction using procedure in genexus without Business Componet


I'm just learning more about genexus and wanted to know if there was a way to do this.

As the title says, i just want to know how to add a sublevel Transaccion without using Business component, I have readed the majority of "new", "for each", "blocking" and other stuff on genexus wiki, but to no luck.

For example, let's say we have this transaccion:

Person
{
 PersonId
 PersonName

 City
 {
  CityId
  CityName
 }
}

I have a record with a Person, and want to add his City, how would i do it?


Solution

  • Suppose you hold the Person Id in &PersonId, then you would issue:

    new
      PersonId = &PersonId
      CityId = ...
      CityName = ...
    when duplicate   // This is optional
      ...  // do something if there already exists a tuple PersonId/CityId with those values
    endnew
    

    In this sample, I am assuming you have a table Person with key PersonId and a table PersonCity with key PersonId, CityId

    Don't forget to commit the transaction explicitly or implicitly (by having the procedure property Commit on Exit set to yes).