Adding a record using a browse

Chaos

New Member
Hi
I would like to know if anyone could help me with sample code on how to add a record to a browse.
 

NickA

Member
For updateable browses..

You need to use 'INSERT-ROW' to create a blank line in the browse, which also sets the 'NEW-ROW' attribute.

Use 'CREATE-RESULT-LIST-ENTRY' to end the process of adding the record, which synchs up the new data with the browse.

I'd recommend an 'Add' button that triggers the 'INSERT-ROW', then put all of the code to actually create the record in the 'ROW-LEAVE' trigger for the browse, ending with 'CREATE-RESULT-LIST-ENTRY'. Nice and tidy that way.

An example would look something like the following (It might not be completely correct, but it should give you the general idea)..

<CODE SNIPPET---

ON CHOOSE OF btnAdd DO:
/* User clicks on 'Add' button - insert a row into the updateable browse */
{&BROWSE-NAME}:INSERT-ROW("AFTER":U).
END.

ON ROW-LEAVE OF {&BROWSE-NAME} DO:

/* User leaves row. If adding a new record, create it in the DB, and create the result list entry to synch things up */

IF NOT BROWSE {&BROWSE-NAME}:NEW-ROW THEN
RETURN.

CREATE {&FIRST-TABLE-IN-QUERY-{&BROWSE-NAME}}.
ASSIGN {&FIRST-TABLE-IN-QUERY-{&BROWSE-NAME}}.

BROWSE {&BROWSE-NAME}:CREATE-RESULT-LIST-ENTRY().

END.

---CODE SNIPPET>
 

JLCUENCA

New Member
You want to insert the record with a button or as a result from a process?

Are you using smart-objects? because then is very easy add a smart-panel with all the actions to delete, add, update, etc.
 
Top