AppeonMobile.CordovaPlugin object

SetTimeout function

Description

Sets the time out value in milliseconds. By default it is 5 seconds. If 0, no timeout period is in effect.

Syntax

SetTimeout ( milliseconds )

Return value

None

Usage

This function is required when ExecJavaScriptWithReturn is called, because the Cordova plugin may connect with the network, or plugin may have bugs or invalid parameters, etc.

This function is required when @ (instead of @EventName) is used to wait for the execution result.

AssociateJSwithPB function

Description

Associates a Cordova plugin (JavaScript object) with a PowerBuilder object. After associated, the PowerBuilder object will have all of the methods and properties that the JavaScript object has.

Syntax

AssociateJSwithPB ( string, PBobject )

Parameter

string - The JavaScript object defined by the Cordova plugin. If it is not a global object, then it will need to be created first before it can be associated with.

PBobject - The PowerBuilder object. If callback functions are used in the JavaScript object, then the corresponding callback events should be defined in this object.

Return value

None

Code example

Oleobject ole
Ole = Create Oleobject
//Connects with AppeonMobile.CordovaPlugin
ole.Connecttonewobject ( "AppeonMobile.CordovaPlugin" )
//Associates with the plugin object
//navigator.contacts is a global object according to the Cordova help
ole.AssociateJSwithPB ( "navigator.contacts", this )

ExecJavaScript function

Description

Executes a line of JavaScript code and returns no value. This function can be used to execute a line of JavaScript code that returns no value (asynchronous execution).

To execute a line of JavaScript code that returns a value, call the ExecJavaScriptWithReturn function.

To execute a line of JavaScript code that contains a callback function, it is not recommended to use ExecJavaScript, as it will be very complicated to write scripts to use the callback function in ExecJavaScript; instead, it is recommended that the user associates with the JavaScript object where the function will be called, and then use dot notation to execute this function. Dot notation will be described more in Using dot notation.

Syntax

ExecJavaScript ( string )

Return value

None

Usage

This function must be used to execute the JavaScript code that creates an object. If the JavaScript code contains a string, then the string must be included in double quotation marks. The semi colon (;) at the end of the JavaScript code can be preserved or omitted.

Example 1:

JavaScript code:

var myContact = navigator.contacts.create ({"displayName": "Test User"});

Corresponding PowerBuilder code:

oleobject.ExecJavaScript ('var mycontact = navigator.contacts.create ({"displyaName":"TestUser"});')

Example 2:

JavaScript code:

var options = new ContactFindOptions ();

Corresponding PowerBuilder code:

lole_cordova.ExecJavaScript ("var options = new ContactFindOptions();")

Code example

Oleobject lole_cordova
lole_cordova = Create OleObject
//connects with AppeonMobile.CordovaPlugin
lole_cordova.connecttonewobject ( "AppeonMobile.CordovaPlugin" ) 
//associates this PB object with a JS object navigator.contacts
lole_cordova.AssociateJSwithPB ( "navigator.contacts", this )
//sets the timeout value
lole_cordova.SetTimeout (10000)
//executes a line of JS code
//creates a new ContactFindOptions object
lole_cordova.ExecJavaScript ( "var options = new ContactFindOptions();" )
//associates with the new object
lole_cordova.AssociateJSwithPB ( "options", This )
//as the value of filter is a string, include "Test" in quotation marks
lole_cordova.ExecJavaScript ( "options.filter=~"Test~"" )
//as the multiple object is a boolean, no need to include it in quotation marks
lole_cordova.ExecJavaScript ( "options.multiple=true" )

ExecJavaScriptWithReturn function

Description

Executes a line of JavaScript code and returns the result.

Syntax

ExecJavaScriptWithReturn ( string )

Return value

String.

Returns a string if successful. If an object is returned, the object properties will be described in a JSON-format string.

Returns an empty string if timeout is reached (possible causes for timeout: script is too long, script has errors, parameter is incorrect, etc.).

Code example

If the JavaScript code contains a string, then the string must be included in double quotation marks. The semi colon (;) at the end of the JavaScript code can be preserved or omitted.

String ls_Return
Oleobject lole_cordova
lole_cordova = Create OleObject
//connects the PB OLEObject with AppeonMobile.cordovaPlugin
lole_cordova.connecttonewobject ("AppeonMobile.CordovaPlugin") 
//associates this PB object with a JS object navigator.contacts
lole_cordova.AssociateJSwithPB ("navigator.contacts", this)
//sets the timeout value
lole_cordova.SetTimeout (10000)
//executes a line of JS code and returns no value
lole_cordova.ExecJavaScript ("var options = new ContactFindOptions();")
//executes a line of JS code and returns a value. The value is a string in the JSON format containing all of the properties of options object
ls_Return = lole_cordova.ExecJavaScriptWithReturn ("options")

ExecJavaScriptGetLastFuncCallRetVal function

Description

Gets the return value of the last method that uses callback functions. Executing this function will get the return value of the last executed JavaScript method that uses callback functions.

Syntax

ExecJavaScriptGetLastFuncCallRetVal ( )

Return value

String.

Code example

oleobject ole_orientation
ole_orientation = Create oleobject
Integer li_Return
String ls_Return
li_Return = ole_orientation.connecttonewobject ("AppeonMobile.CordovaPlugin")
ole_orientation.AssociateJSwithPB ("navigator.compass", this)
//ls_Return stores the return value of the callback event
ls_Return = ole_orientation.watchHeading ('@', '@', '{frequency: 3000}')
//gets the return value of watchHeading()
ls_Return = ole_orientation.ExecJavaScriptGetLastFuncCallRetVal()
ole_orientation.watchHeading ('@ue_contactfind', '@ue_contactfind_error', '{frequency: 50}')
//gets the return value of watchHeading()
ls_Return = ole_orientation.ExecJavaScriptGetLastFuncCallRetVal()
ole_orientation.disconnectobject()

GetLastErrorExecJS function

Description

Gets the error information if the JavaScript code has an error, including incorrect function name, misspellings, execution errors etc. The error information is returned from the JavaScript code. You can use GetLastErrorExecJS together with oe_execjserror (string errormessage) to help determine the cause.

Syntax

GetLastErrorExecJS ( )

Return value

String.

The following error types can be detected by GetLastErrorExecJS:

  • Missing "@" when using the callback event

  • Misspelling of the JavaScript function name or object property name in a dot notation

  • Misspelling of the Appeon-provided function name

  • Incorrect JavaScript object name or function name such as case mismatch

  • Format error of the JSON string, such as missing open bracket ("[")

  • Incorrect parameter or invalid property value in a dot notation of calling JavaScript code

The following error types cannot be detected by GetLastErrorExecJS:

  • Missing "@" if you do not want to use the callback event

  • Misspelling of the JavaScript object property name

  • Incorrect keyword name in a JSON string

oe_execjserror event

Description

Occurs when the JavaScript code has an error, including incorrect function name, misspellings, and execution errors etc. It is an asynchronous event.

Syntax

oe_execjserror ( string errormessage )

Usage

To use this event, you need to add an event with the same name in the PowerBuilder object that is bound with the JavaScript object via AssociateJSwithPB ( string, PBobject ).