Step 12. Display Message Box for Employee Update

This step will extend the Update from a List web page, to display a Message Box when the employee details update fails, displaying the error messages returned by the xEmployeeDataServer server module.

1.  Switch to the Update from a List web page in the editor and select the Design tab.

2.  From the Controls tab, drag a Message Box control onto the web page. It will not be shown on the Design view.

3.  The message box will currently have focus in the editor. On the Details tab, change its Name to MessageBox.

4.  Add code to the web page CreateInstance event routine to set the Message Box image and buttons.

Evtroutine Handling(#com_owner.createInstance)

#com_self.loadDropdowns

#MessageBox.Title := 'Update Employee Details'

#MessageBox.Image := Information

#MessageBox.buttons := OK

Endroutine

 

5.  Extend the UpdateEmployee.Completed event in the SaveEmployee method based on the following:

Before executing UpdateEmployee, clear all messages.

 

Extend the If in the UpdateEmployee.Completed event

If . . .

. . .

Else

Set Message Box Caption to 'Please correct these errors'

For each Message in Sys_MsgQ.Messages

Add Message.text to MessageBox.Captions collection

EndFor

Invoke Message Box Show method.

End If

     Your code should look like the following:

Mthroutine Name(SaveEmployee)

Define_Map For(*INPUT) Class(#xEmployeeIdentification) Name(#EmployeeID)

Define_Com Class(#iiixEmployeeDataServer.save) Name(#UpdateEmployee)

#xEmployeeIdentification := #EmployeeID

#SYS_MSGQ.ClearAll

#UpdateEmployee.ExecuteAsync( #xEmployee #IO$STS )

Evtroutine Handling(#UpdateEmployee.Completed)

If (#IO$STS = OK)

#xEmployee := *null

#Label_Details.Caption := ""

Clr_List Named(#NotesList)

Else

#MessageBox.Caption := 'Please correct these errors:'

For Each(#message) In(#SYS_MSGQ.Messages)

#MessageBox.Captions.add( #message.Text )

Endfor

#MessageBox.show

Endif

Endroutine

 

Endroutine 

     Note: Select the Message Box definition in the Source and press F2 to display the Features tab, showing the component's properties, events and methods.

6.  Recompile the Update from a List web page.

7.  Re-test the Update from a List web page application.

     Select an employee and clear a number of fields and click Save.

     The web page's Message Box should be displayed: