Examples

Update all work orders that are on the state ONSITE to have a new address and send these changes to the sever:

procedure UpdateOnSiteWoAddresses {
   parameter NewAddress Text;

   variable Wo Structure(WorkOrder);

   execute {
      for WorkOrder i where [ i.Objstate = "ONSITE" ] into Wo {
         set Wo.AddressLine1 = NewAddress;
         saveAndSend Wo
      }
   }
}

Set the default CreatedAt and Objstate on a work order before creating:

@Overtake
procedure EntityPrepare<WorkOrder> Structure(WorkOrder) {
   execute {
      super(Record) into Record;
      call DateTime.Timestamp() into Record.CreatedAt;
      set Record.Objstate = "NEW";
      return Record;
   }
}

Utility procedure to create a new work order and send it to the server:

procedure CreateNewWo Structure(WorkOrder) {
   parameter Description Text;

   variable Wo Structure(WorkOrder);

   execute {
      create Wo;      
      set Wo.Description = Description;
      saveAndSend Wo
      return Wo;
   }
}

Utility procedure that saves a row to the local database, sends it to the server then deletes the local row:

procedure SaveLocation {
   parameter Position Text;
   variable Loc Structure(UserLocation);

   execute {

      if [Position = null] {
           error("Invalid position");
      }

      create Loc;

      call DateTime.Timestamp() into Loc.CreatedAt;
      set Loc.Location = Position

      saveAndSend Loc;
      deleteLocal Loc;
   }
}