In this step you will extend your web page to add a record to the department table. To do this you simply need to:
1. Switch to your Departments Server Module in the editor. Select the Go To tab. If this is not already open, use the Tabs menu on the Home ribbon to open it. This lists its srvroutines under Routine.
Double click on Save to position to this routine in the editor.
2. Review the Save logic. A Check_For command tests whether a record exists for the input department code (xDepartmentCode) and then Updates or Inserts to the table, as appropriate.
Your web page can execute the Save srvroutine to insert a new record or update an existing record.
3. Switch to your iiiMaintDepartment web page in the editor. Select the Design tab.
4. Drag a push button into the second row.
a. Select the Layout ribbon and change Alignment to Top Left and Flow to Right.
b. Change margin Top to 20 and margin Left to 20.
c. Using the Detail tab, change the button Caption to Insert.
d. Change the Name to Insert
e. Create a Click event for the Insert button.
5. Create a Save method routine. This routine should have a similar structure to the Fetch routine:
Define a component for the xDepartmentsDataServer Save srvroutine, named SaveDepartment
Execute SaveDepartment asynchronously passing and receiving fields in Group_By xDepartments and IO$STS.
Within an event routine for SaveDepartment.Completed, check If IO$STS is equal OK, and assign fields in Group_by xDepartments to their default value:
Your code should look like the following:
Define_Com Class(#iiixDepartmentsDataServer.Save) Name(#SaveDepartment)
#SaveDepartment.executeasync( #xDepartments #io$sts )
If (#IO$STS = OK)
#xDepartments := *default
6. Complete the Insert button click event by adding code to invoke the Save method.
7. Compile and Execute the web page. Enter a department code which doesn't exist such as 50 with any description and click Insert. Note that when successful, the Save routine clears the fields.
Enter 50 and retrieve the new department record.
8. Try to Save a new record, leaving Description blank. Notice that the Department Code is not cleared, indicating that the insert failed. The Department Description has a "must not be blank" validation rule.