Inside a mobile Javascript action
Every time an event fired within the app must be captured to perform something, an action must be defined an linked to the event. Basically, this is what the Web Designer allows to define. An action is expressed as a set of Javascript instructions.
This language has been setchosen because it can be interpreted by both the platforms: iOS and Android, so you can define once the application and use it on any platform, thanks to the portability of Javascript. reload Platform provides a series of utility methods you can incllude in your Javascript scriptlets, described below.
Independently of the javascript code you'll include in your actions, bear in mind that the javascript code must be interpreted on the embedded js interpreter for iOS and Android. These interpreters are not as good as the ones available for desktop computers. showm There are a view limitations you have to take into account when writing javascript code:
Do not use
Correct solution
if (variable)
if (variable!=null)
var1===var2
var1==var2
var1!==var2
var1!=var2
eval(jsonString)
JSON.parse(jsonString) //jsonString must be !=null and !=""
var a = b || c
var a = b!=null?b:c;
replace a char var newStr = str.replace(/-/g,"")
var oRegExp = new RegExp("-","g"); var newStr = str.replace(oRegExp, "");
Independently of the type of component embedding the Javascript (a mobile action or a business component), a few predefined objects are always available:
vo
the javascript representation of the json string passed through the Ajax request
optionalParams
passed as input parameters from the component invoking the action
Moreover, some of the buit-in mobile javascript methods are related to SQL instructions. For those functions, Platform allows to specify SQL instructions including binding variables. These binding variables are always defined using the notation:
:XXX
where XXX is the variable name, always in upper case.
These variables will be automatically replaced by the corresponding values available at user session level.
The user session is composed of a set of variables:
predefined variables, automatically set by Platform, when the user starts the app
custom variables, defined using the setUserSessionVariable mobile javascript method
input parameters, passed to the business component/javascript
The predefined variables are:
Variable name
Description
:APPLICATION_ID
application identifier
:BASE_URL -server base url
:COMPANY_ID
company identifier (used in case the app supports partitioned data)
:SITE_ID
site identifier
:USERNAME
current user
:USERDESC
current user description
:UUID or :DEVICE_ID
device id, i.e. a unique identifier for a specific device (more specific than the username)
:LANGUAGE_ID
current user
:DOCUMENTS_DIR
absolute path within the mobile device, where files are stored;it is a folder inside the “customFiles” default app folder.
:TODAY
current date
:NOW
current date+time
:YEAR
current year
:GPS_LATITUDE
current latitude
:GPS_LONGITUDE
current longitude
:GPS_ALTITUDE
currentaltitude
:GPS_SPEED
currentspeed
:APP_VERSION
current app versione
:LAST_SYNC_DATE
last sync date
Last updated