Skip to main content

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 useCorrect solution
if (variable)if (variable!=null)
var1===var2var1==var2
var1!==var2var1!=var2
eval(jsonString)JSON.parse(jsonString) //jsonString must be !=null and !=""
var a = b || cvar 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_IDapplication identifier
:BASE_URL -server base url
:COMPANY_IDcompany identifier (used in case the app supports partitioned data)
:SITE_IDsite identifier
:USERNAMEcurrent user
:USERDESCcurrent user description
:UUID or :DEVICE_IDdevice id, i.e. a unique identifier for a specific device (more specific than the username)
:LANGUAGE_IDcurrent user
:DOCUMENTS_DIRabsolute path within the mobile device, where files are stored;it is a folder inside the “customFiles” default app folder.
:TODAYcurrent date
:NOWcurrent date+time
:YEARcurrent year
:GPS_LATITUDEcurrent latitude
:GPS_LONGITUDEcurrent longitude
:GPS_ALTITUDEcurrentaltitude
:GPS_SPEEDcurrentspeed
:APP_VERSIONcurrent app versione
:LAST_SYNC_DATElast sync date