Webevent Function 1

LANSA

Webevent Function 1
In these steps you will create a webevent function that presents two buttons (Find and Submit) and an input field (Employee Number).

Clicking on the Find button will resubmit the same function, read the Personnel System file and return the Employees full name. Clicking on the Submit button will resubmit the same function, and simply issue a message.


1.Work with process SET_203 and create a new function named SET203B, with description Basic Webevent B.

Specify New function type 2, Copy existing Process SET_203 Function SET203A.

2.Take a couple of minutes to read the comments in the source code.
3.Below the comment Button Components, define two alphanumeric fields with length 1 called S_203FIND and S_203SUBM:

DEFINE FIELD(#S_203FIND) TYPE(*CHAR) LENGTH(001)
DEFINE FIELD(#S_203SUBM) TYPE(*CHAR) LENGTH(001)

These two fields have the same name as components S_203FIND and S_203SUBM. Because of this, when the two fields are included as hidden fields in the REQUEST statement, LANSA for the WEB will replace them with the actual buttons defined in the Web components.
4.Below the comment Other Fields define four alphanumeric fields with length 10 called PROC_FIND, FUNC_FIND, PROC_ SUBM and FUNC_SUBM:

DEFINE FIELD(#PROC_FIND) TYPE(*CHAR) LENGTH(010) DESC('Process called when FIND button pressed') DEFAULT(*PROCESS)
DEFINE FIELD(#FUNC_FIND) TYPE(*CHAR) LENGTH(010) DESC('Function called when FIND button pressed') DEFAULT(*FUNCTION)
DEFINE FIELD(#PROC_SUBM) TYPE(*CHAR) LENGTH(010) DESC('Proc. called when SUBMIT button pressed') DEFAULT(*PROCESS)
DEFINE FIELD(#FUNC_SUBM) TYPE(*CHAR) LENGTH(010) DESC('Func. called when SUBMIT button pressed') DEFAULT(*FUNCTION)

At this point, look at component S_203FIND to see an example of how these components work.

<INPUT TYPE="BUTTON" NAME="S_203FIND" VALUE="Find" onClick="document.LANSA.AS_CLICKED.value='FIND.CLICK';HandleEvent('<RDML MERGE="PROC_FIND">','<RDML MERGE="FUNC_FIND">')">

This HTML defines a button on a web page. When it is clicked (onClick=), it will set the value of the field S_CLICKED to the value FIND.CLICK. It will then invoke a Java Script function called HandleEvent, which is present in your DEFAULT_SCRIPT page, shipped with LANSA for the Web. HandleEvent receives two parameters, the Process and the Function name to be submitted. In this case, we are passing the values contained in the fields PROC_FIND and FUNC_FIND. Exactly the same applies to S_203SUBM.

Note how #S_CLICKED is referred to as document.LANSA.AS_CLICKED in the html. The A indicates that the field is of type Alphanumeric. It has been is added by LANSA for the WEB for internal. As far as any reference to it from Java Script, the RDML field #S_CLICKED must be referred to as AS_CLICKED.


5.Include all required fields in the #PANELDATA group of fields. All the fields will be hidden except for the Employee Number:

GROUP_BY NAME(#PANELDATA) FIELDS(#EMPNO (#FULLNAME *OUTPUT *NOID) (#S_CLICKED *HIDDEN) (#S_203FIND *HIDDEN) (#S_203SUBM *HIDDEN) (#PROC_FIND *HIDDEN) (#FUNC_FIND *HIDDEN) (#PROC_SUBM *HIDDEN) (#FUNC_SUBM *HIDDEN))
6.Modify the CASE statement so that it caters for the new options, that is for when the Find button is clicked and for when the Submit button is clicked:

CASE OF_FIELD(#S_CLICKED)
********
WHEN VALUE_IS('= FORM.INITIALIZE')
EXECUTE SUBROUTINE(INIT_EVENT)
********
WHEN VALUE_IS('= FIND.CLICK')
EXECUTE SUBROUTINE(FIND_EVENT)
********
WHEN VALUE_IS('= SUBMIT.CLICK')
EXECUTE SUBROUTINE(SUBM_EVENT)
********
ENDCASE

7.Finally, create the new subroutines that were referred to in the CASE statement:

**********
SUBROUTINE NAME(FIND_EVENT)
FETCH FIELDS(#SURNAME #GIVENAME) FROM_FILE(PSLMST) WITH_KEY(#EMPNO) IF_STATUS IS(*OKAY)
USE BUILTIN(BCONCAT) WITH_ARGS(#SURNAME #GIVENAME) TO_GET(#FULLNAME)
MESSAGE MSGTXT('Employee found. Message issued by function SET203B')
ELSE
MESSAGE MSGTXT('Employee not found. Message issued by function SET203B')
CHANGE FIELD(#EMPNO) TO(*NAVAIL)
ENDIF
ENDROUTINE
**********

SUBROUTINE NAME(SUBM_EVENT)
MESSAGE MSGTXT('Submit subroutine executed. Message issued by function SET203B')
CHANGE FIELD(#EMPNO) TO(*BLANK)
ENDROUTINE
8.Compile and execute this function. To execute this function, open a browser session. In the address entry field of the browser, type:

http://nnn.nnn.nnn.nnn:xx/CGI-BIN/LANSAWEB?PROCFUN+set_203+set203b+ppp

where:
nnn.nnn.nnn.nnnis the IP address of the web server you are connecting to.
xxis the port number where your web server has been configured to run. If your web server uses the default port 80, this parameter is not required.
Pppis the partition identifier of the partition where you imported the SET material.