Step 3. Add Push Buttons and Click Event Logic

1.  On the Controls tab, select the Favorites group of controls.

     Drag a Push Button onto column 2, in row 1.

2.  Using the Layout ribbon change its Alignment to Bottom Center and Flow to Up.

3.  Drag a second Push Button onto column 2, row 1.

     Change its Alignment to Bottom Center and Flow to Up.

4.  Hold down the Shift key and click on both buttons.

     Change their margin Bottom to 20.

5.  Use the Details / Properties tab to set up the two push buttons as follows:

Property Value

Caption

Save

Name

SAVE

 

 

Property

Value

Caption

Close

Name

CLOSE

 

     Your form should look like the following:

6.  Use the Details / Events tab and double click on the event to create a Click event for each button.

7.  Add code to the CLOSE Click event to close the form. Your code should look like the following:

Evtroutine Handling(#CLOSE.Click)

#com_owner.closeForm

Endroutine
 

8.  At the top of your code, below the Define_Com statements, define a GROUP_BY to include all fields on the form. Your code should look like the following

Group_By Name(#empdata) Fields(#xEmployeeIdentification #xEmployeeTitle #xEmployeeSurname #xEmployeeGivenNames #xEmployeeStreet #xEmployeeState #xEmployeeCity #xEmployeePostalCode #xEmployeeDateofBirth #xEmployeeGender) 

     You can use AutoComplete to prompt and then select each field. Begin typing each field name (#xEmpl…) and press enter on the required field in the AutoComplete prompt.

     Alternatively, type GROUP_BY and press F4 to use the Command Assistant and then the Fields by Table tab.

a.  In the Command Assistant, enter the name of the Group_by #EMPDATA.

b.  Position the cursor in the Fields parameter.

     Note: You may prefer to float and resize the Command Assistant tab so that it easily shows more information.

Notes:

9.  Click in the Fields parameter and select the Fields by Table tab and enter xe in the Filter / Table Name:

10. Expand the table xEmployee and hold down the Shift key, select xEmployeeIdentification and then xEmployeePostalCode and press Enter. Your Assistant dialog should now look like the following:

     Note: The FIELDS parameter has been expanded in this image.

     Your Group_by should look like the following:

Group_By Name(#empdata) Fields(#xEmployeeIdentification #xEmployeeTitle #xEmployeeSurname #xEmployeeGivenNames #xEmployeeDateofBirth #xEmployeeGender #xEmployeeStreet #xEmployeeCity #xEmployeeState #xEmployeePostalCode) 

11. Add an INSERT command to the SAVE.Click event routine. This should insert the Group_by EMPDATA to the table xEmployee. Your event routines code should look like the following:

Evtroutine Handling(#SAVE.Click)
Insert Fields(#EMPDATA) To_File(xEmployee)
Endroutine
 

  Select the INSERT command and press F1 to open its definition in the Technical Guide to see all its parameters. For example, note that the CHECK_ONLY(*YES) parameter enables "trial" insert to be performed. This would enable a check for errors, before continuing.

12. Compile your form and execute it.

13. Without entering any data, click the Save button; Your form should look like the following:

14. Click on the WorE0 down button on the Status Bar to scroll through all the validation error messages.

     Having completed the Repository tutorials, you should know that the error messages have been generated by the table's OAM, based on the field and table validation rules.

     The Status Bar monitors the Sys_Msgq.MessageAdded and Sys_Msgq.MessageRemoved events and retrieves and displays all messages.

  Fields with validation errors are automatically highlighted. You do not need to code this logic.

15. The INSERT command has a default parameter VAL_ERROR(*LASTDISPLAY). In a form this will branch to the ENDROUTINE for the event or method routine. To demonstrate this point, add the following MESSAGE command after the INSERT command in the SAVE.Click event routine.

Message Msgtxt('This message only displayed on successful INSERT')
 

     Recompile your form and retest "add a blank record". Scroll to the end of the status bar messages. The above message will not be shown.

     In your applications, you will often change the validation error parameter on I/O commands to VAL_ERROR(*Next), so that your own logic can handle error conditions.

16. Insert valid data to add a new employee. Employee Identification is a 10 alphanumeric. Try a value lower than 100066.

     Observe that your "This message displayed on successful INSERT" is now displayed.

     Note also that at this stage the fields have not been re-initialized.

17. Change the message following the INSERT command as follows:

Message Msgtxt('Employee number ' + #xEmployeeIdentification + ' has been added')
 

     Suitable parameter values can be written as expressions.

     In your own applications you will usually use a message file message for this type of feedback.

18. After the INSERT, add code to reset the employee fields to their default values, using the Group_by:

#EMPDATA := *default
 

19. Recompile your form and retest it by adding another employee record. All field values should be reset to their default values as defined in their Repository field definitions, in this case they are all blank or zeroes.

     Note that your new message Employee number 999999 has been added is displayed in the status bar.

20. With your form still running after the successful insert, try to insert another blank record. Review the status bar messages and note that the "Employee number 100050 has been added" has been cleared.

     An event routine has an OPTIONS setting with default values as follows:

Evtroutine Handling(#SAVE.Click) options(*CLEARERRORS *CLEARMESSAGES)
 

     Each time an event routine is executed, by default, it clears field errors conditions and messages.