Step 3. Add a Routine to Listen for the EMPLOYEE_CHANGED Event
In this step you will add an event routine to the Employees filter to listen for the EMPLOYEE_CHANGED event.
1. Locate and open the Employees filter iiiCOM07.
2. Display the Source tab.
3. Add an event routine to listen for an avEvent signal:
Evtroutine Handling(#Com_Owner.avEvent) WithId(#EventId) Options(*NOCLEARMESSAGES *NOCLEARERRORS) WithAinfo1(#Ainfo1)
Endroutine
The avEvent event is an event that is signaled by the framework when the avSignalEvent method is called. The event routine receives the event being signaled along with any alphanumeric or numeric data that accompanies the event.
4. Next add a CASE command to test which event has been signaled in the event routine:
Case #EventId.Value
EndCase
It is important to test to make sure that the EventID matches one of the events that this event routine handles as the event being signaled might not apply to the component in which you have placed this event routine.
5. Then place appropriate WHEN VALUE_IS commands to handle various event ids that apply to this component. In this case we only want to handle the EMPLOYEE_CHANGED event:
When (= EMPLOYEE_CHANGED)
Your code will now look like this:
6. Next add code to save the current key values from overwrites:
Inz_List #Save_Keys 1
7. Assign the value passed by the signaled event to the EMPNO field:
#EmpNo := #AInfo1
8. Start updating the instance list:
Invoke Method(#avListManager.BeginListUpdate)
9. Fetch the details of the employee that has been updated:
FETCH FIELDS(#SURNAME #GIVENAME #EMPNO #SALARY) FROM_FILE(PSLMST) WITH_KEY(#EMPNO)
10. Update the entry in the instance list:
Use Builtin(BCONCAT) With_Args(#GIVENAME #SURNAME) To_Get(#FULLNAME)
Invoke #avListManager.AddtoList Visualid1(#EMPNO) Visualid2(#FULLNAME) NColumn1(#SALARY) AKey1(#EMPNO)
11. Complete the instance list update:
Invoke Method(#avListManager.EndListUpdate)
12. Lastly restore the saved key values:
Get_Entry 1 #Save_Keys
Your finished code will look like this:
13. Compile the filter.