Exercise 4: AJAXEX4 – Using the Instance List
The Steps
- Copy and paste the DHTML-JavaScript code in AJAX Page AJAXEX4.HTM using NOTEPAD and save it into your Framework private working folder as an AJAX page file named AJAXEX4.HTM.
- Copy and paste the AJAX function code in AJAX Function AJAXEX4 into an RDML function named AJAXEX4 into your VL-IDE. Compile RDML function AJAXEX4 so that it is executable on your web server.
- In the shipped demonstration business object “Resources” add command AJAXEX4 as a new instance level command (like Details, Transfer, etc).
- Snap AJAXEX4.HTM and AJAXEX4 into as the handlers associated with command AJAXEX4 like this:
Save, restart and execute your Framework in a web browser. Select the “Resources” business object and build a list of employees. Select one. This should display the default “Details” command. Switch to the AJAXEX4 tab and you should see the details of the employee displayed like this (in VLF.WEB):
Or this (VLF.NET):
This AJAX example is designed to demonstrate how business object instance list details are passed into AJAX pages.
They are passed into the VF_AJAX_Execute function as a JavaScript instance list object which contains these properties and arrays:
Name | Type |
strVisualID1 |
String. Visual ID1 |
strVisualID2 |
String. Visual ID2. |
strBusinessObjectType |
String. Business Object Type. |
arraystrAKeyN |
Array[5] String. AKey values. |
arraynumNKeyN |
Array[5] numbers. NKey values. |
intAColumnCount |
Count of additional alpha columns. |
arraystrAColumn |
Array of additional alpha columns. |
intNColumnCount |
Count of additional numeric columns. |
arraynumNColumn |
Array of additional numeric columns. |
<all others> |
There may be other values and properties in this object. You should NOT reference them in your code to avoid future version incompatibilities and/or failures. |
Note 1: Some of these values may be blank padded and needed to be trimmed for presentation.
Note 2: The Framework-AJAX facility is primarily designed to be used in full screen command handlers that largely act as on their own, as demonstrated in the preceding exercises 1 through 3.
<HTML>
<HEAD id='HEAD_Tag'>
<link rel='stylesheet' type='text/css' href='vf_vs001.css' >
<script>
/* ======================================================================== */
/* ======================== Handle Page Initialization ==================== */
/* ======================================================================== */
function VF_AJAX_Initialize()
{
/* Insert the variable style sheet (ie: XP, WIN, WEB style) into this page */
{
var objLink = document.createElement("LINK");
objLink.rel = "stylesheet"; objLink.type = "text/css";
objLink.href = STYLESHEET();
document.getElementById("HEAD_Tag").insertAdjacentElement("afterBegin",objLink);
}
/* Finished */
return;
}
/* ======================================================================== */
/* ======================== Handle Page Execution ========================= */
/* ======================================================================== */
function VF_AJAX_Execute(objInstance)
{
/* Put the current instance list entry EMPNO onto the clipboard */
/* The employee number is in AKey number 3, which is Javascritp array entry 2 */
Put(objInstance.arraystrAKeyN[2],"EX4","EMPNO");
/* Request that the server do a FETCH operation using the employee number */
SENDREQUEST(window,"","FETCH","",FETCH_response);
/* Finished */
return;
}
/* ======================================================================== */
/* ======================= Handle Page Termination ======================== */
/* ======================================================================== */
function VF_AJAX_Terminate()
{
return;
}
/* -------------------------------------------------------- */
/* Rationalized virtual clipboard access to name space AJAX */
/* -------------------------------------------------------- */
function Put(val,np2,np3,inst) {AVSAVEVALUE(val,"AJAX",np2,np3,inst);}
function GetA(np2,np3,inst) {return(AVRESTOREAVALUE("","AJAX",np2,np3,inst));}
function GetN(np2,np3,inst) {return(AVRESTORENVALUE(0,"AJAX",np2,np3,inst));}
/* ---------------------------------- */
/* Handle server responding to LOAD10 */
/* ---------------------------------- */
function FETCH_response(strFunction,strRequest,strPayload,objObject,flagFatalError,strFatalMessage)
{
/* Handle a fatal error */
if (flagFatalError) { alert(strFatalMessage); SETBUSY(false); return; }
/* Put the employee number out onto the screen */
Vis_EMPNO.innerText = GetA("EX4","EMPNO");
/* Get the IO Status and handle found and not found */
if (GetA("EX4","IO_STS") == "OK") /* Employee was found */
{
Vis_SURNAME.innerText = GetA("EX4","SURNAME");
Vis_GIVENAME.innerText = GetA("EX4","GIVENAME");
Vis_SALARY.innerText = GetN("EX4","SALARY").toString();
Vis_POSTCODE.innerText = GetN("EX4","POSTCODE").toString();
DIV_Table.style.visibility = "visible"; DIV_Table.style.display = "inline";
DIV_Message.style.visibility = "hidden"; DIV_Message.style.display = "none";
}
else /* Employee was not found */
{
DIV_Message.children(0).innerText = "Employee number " + Vis_EMPNO.innerText + " could not be found";
DIV_Message.style.visibility = "visible"; DIV_Message.style.display = "inline";
DIV_Table.style.visibility = "hidden"; DIV_Table.style.display = "none";
}
/* Drop busy status */
SETBUSY(false);
/* Finished */
return;
}
</script>
</HEAD>
<BODY id='BODY_Tag'>
<br/><br/><br/>
<P align='center'>Instance List Example</p>
<div id='DIV_Message'>
<P align='center'>Loading ... please wait</p>
</div>
<div id='DIV_Table' style='visibility:hidden;display:none;'>
<table>
<tr><td>Employee Number</td><td id='Vis_EMPNO'></td></tr>
<tr><td>Last Name</td><td id='Vis_SURNAME'></td></tr>
<tr><td>First Name</td><td id='Vis_GIVENAME'></td></tr>
<tr><td>Current Salary</td><td id='Vis_SALARY'></td></tr>
<tr><td>Zip Code</td><td id='Vis_POSTCODE'></td></tr>
</table>
</div>
</BODY>
</HTML>
* This is just a simple RDML function.
* It is NOT a WAM.
* It is driven by the virtual clipboard
Function Options(*DIRECT *HEAVYUSAGE)
* Define local fields
Define Field(#REQUEST) Reffld(#STD_OBJ)
Define Field(#MSGDTA) Type(*CHAR) Length(132)
* Get the action the Javascript requested .......
Execute Subroutine(GETA) With_Parms(SYSTEM REQUEST 1 #REQUEST)
* Now switch on the requested action
Case Of_Field(#REQUEST)
* Get details of an employee
When Value_Is('= FETCH')
Execute Subroutine(FETCH)
Otherwise
Use Builtin(BCONCAT) With_Args('Unknown request' #REQUEST 'received by' *FUNCTION) To_Get(#MSGDTA)
Abort Msgid(DCM9899) Msgf(DC@M01) Msgdta(#MSGDTA)
Endcase
* Finished
Return
* Get details of an employee
Subroutine Name(FETCH)
* Get the requested employee number
Execute Subroutine(GETA) With_Parms(EX4 EMPNO 1 #EMPNO)
* Fetch the details
Fetch Fields(#Surname #GiveName #PostCode #Salary) From_File(Pslmst) With_Key(#Empno)
* Send back the IO status + the details
Execute Subroutine(PUTA) With_Parms(EX4 IO_STS 1 #IO$STS)
Execute Subroutine(PUTA) With_Parms(EX4 SURNAME 1 #SURName)
Execute Subroutine(PUTA) With_Parms(EX4 GIVENAME 1 #GIVENAME)
Execute Subroutine(PUTN) With_Parms(EX4 POSTCODE 1 #POSTCODE)
Execute Subroutine(PUTN) With_Parms(EX4 SALARY 1 #SALARY)
Endroutine
* =====================================================
* Rationalized subroutines for virtual clipboard access
* =====================================================
Subroutine Name(PUTA) Parms((#NP2 *RECEIVED) (#NP3 *RECEIVED) (#INST *RECEIVED) (#AVAL *RECEIVED))
Define Field(#NP2) Type(*CHAR) Length(28)
Define Field(#NP3) Type(*CHAR) Length(24)
Define Field(#INST) Type(*DEC) Length(7) Decimals(0)
Define Field(#AVAL) Type(*CHAR) Length(256)
Use Builtin(VF_SAVEAVALUE) With_Args(#AVAL AJAX #NP2 #NP3 #INST)
Endroutine
Subroutine Name(PUTN) Parms((#NP2 *RECEIVED) (#NP3 *RECEIVED) (#INST *RECEIVED) (#NVAL *RECEIVED))
Define Field(#NVAL) Type(*DEC) Length(30) Decimals(9)
Use Builtin(VF_SAVENVALUE) With_Args(#NVAL AJAX #NP2 #NP3 #INST)
Endroutine
Subroutine Name(GETA) Parms((#NP2 *RECEIVED) (#NP3 *RECEIVED) (#INST *RECEIVED) (#AVAL *RETURNED))
Use Builtin(VF_RESTOREAVALUE) With_Args(' ' AJAX #NP2 #NP3 #INST) To_Get(#AVAL)
Endroutine
Subroutine Name(GETN) Parms((#NP2 *RECEIVED) (#NP3 *RECEIVED) (#INST *RECEIVED) (#NVAL *RETURNED))
Use Builtin(VF_RESTORENVALUE) With_Args(0 AJAX #NP2 #NP3 #INST) To_Get(#NVAL)
Endroutine