code: public BasePanel onForm(Record record, int iDocMode, boolean bReadCurrentRecord, int bUseSameWindow, Map<String,Object> properties)
      {
          if (record == null)
              record = this.getMainRecord();
          if (record == this.getMainRecord())
          {
              try   {
                  int iSelection = this.getScreenFieldView().getSelectedRow();
                  if (iSelection != -1)
                  {
                      Record recAtTarget = null;
                      this.finalizeThisScreen();  // Validate current control, update record, get ready to close screen.
                      recAtTarget = (Record)((GridTable)record.getTable()).get(iSelection);
                      if (recAtTarget == null)
                          if (record != null)
                              if ((iDocMode & ScreenConstants.DETAIL_MODE) == ScreenConstants.DETAIL_MODE)
                                  if (record.getEditMode() == DBConstants.EDIT_ADD)
                                      if (record.isModified())
                      {
                          record.add();
                          Object bookmark = record.getLastModified(DBConstants.BOOKMARK_HANDLE);
                          recAtTarget = record.setHandle(bookmark, DBConstants.BOOKMARK_HANDLE);
                      }
                  }
                  else
                      record.addNew();
              } catch (DBException ex)    {
                  ex.printStackTrace();
              }
          }
          return super.onForm(record, iDocMode, bReadCurrentRecord, bUseSameWindow, properties);
      }
docs: Create a data entry screen with this main record.
  (null means use this screen's grid record)
  @param record The main record for the new form.
  @param iDocMode The document type of the new form.
  @param bReadCurrentRecord Sync the new screen with my current record?
  @param bUseSameWindow Use the same window?
  @return true if successful.