display.screen.execute()
Description
display.screen.execute() displays a record format of a Rich Display File in the browser (or on a mobile device), waits for the user to respond, and reads the response into the program's fields. It is the equivalent of issuing display.screen.write() immediately followed by display.screen.read(), and of the RPG EXFMT operation. The method can also be called as display.screen.exfmt().
When the user responds, the input-capable fields, response indicators, and function key indicators are populated, and the device feedback positions of the infDS data structure (AID byte, cursor position, and so on) are updated. After the call, display.found() returns true.
Syntax
display.screenName.execute()
display.screenName.execute(dataStructure)
display.screenName.execute(dataStructure, message)
display.screenName.execute(null, message)Parameters
Data structure (Object, optional) - A Profound.js data structure reference, or a plain JavaScript object. If specified, the screen is populated from (and the response is returned into) the data structure or object instead of the program's global fields. If a data structure is not qualified, wrap the parameter with the pjs.ds() API.
Message (any, optional) - Additional information sent to the record format's onmessage event when the screen is rendered. The message can be any JavaScript value, including strings, objects, and arrays.
Return Value
Object - The display file's field collection. The return value is not normally used; the response is read from the global fields or from the data structure passed as the first parameter.
The display file must be open. Calling this method on a closed display throws error 1211 (I/O operation to a closed file).
Examples
Example 1: Show a Screen in a Loop Using the Global Fields
The most common pattern: set the output fields, show the screen, and process the input fields until the user presses the Exit button. The response indicator bound to the button is a global field that the loop tests.
Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.
pjs.defineDisplay("display", "customer.json");
custno = 1001;
custname = "ACME Corporation";
balance = 250.75;
while (!exit) { // exit is set to true when the Exit button is pressed
display.detail.execute(); // Show the screen and wait for the response
if (!exit) {
console.log("The user changed the name to " + custname);
}
}Example 2: Pass and Receive Values with a Plain Object
Instead of the global fields, a plain JavaScript object supplies the values shown on the screen. The user's input is placed back into the same object.
Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.
pjs.defineDisplay("display", "customer.json");
var customer = { custno: 1001, custname: "ACME Corporation", balance: 250.75 };
display.detail.execute(customer); // The screen is populated from the object...
console.log(customer.custname); // ...and the response is returned into itExample 3: Pass and Receive Values with a Data Structure
A qualified data structure defined with extName takes its subfields from the record format, so it always matches the screen. The response is placed into the data structure.
Prerequisite: a Rich Display File named customer.json with a record format named detail that contains the fields custno, custname, and balance, and a button whose response property is bound to an indicator field named exit.
pjs.defineDisplay("display", "customer.json");
// Subfields are taken from the detail record format of customer.json
pjs.define("cust", { type: "data structure", qualified: true,
extName: { file: "customer.json", format: "detail" } });
cust.custno = 1001;
cust.custname = "ACME Corporation";
display.detail.execute(cust); // Use the data structure instead of the global fields
console.log(cust.custname); // The value the user entered
// A data structure that is not qualified must be wrapped with pjs.ds():
// display.detail.execute(pjs.ds("S1"));Example 4: Send a Message to the Screen's onmessage Event
Passes the result of an SQL query to the screen. The second parameter is delivered to the record format's onmessage event as the message variable, where client-side JavaScript can use it (for example to place markers on a map). null is passed as the first parameter so that the global fields are still used.
Prerequisite: a Rich Display File named map.json with a record format named mapscreen whose onmessage event uses the message variable, and a database table named LOCATIONS.
pjs.defineDisplay("display", "map.json");
var markers = pjs.query("SELECT NAME, LATITUDE, LONGITUDE FROM LOCATIONS");
display.mapscreen.execute(null, markers); // markers is available as "message" in the onmessage eventRPG Equivalent
EXFMT