Mobile client GlideForm (g form) scripting and migration

Client scripting for mobile is identical to scripting for the web, with some exceptions. All new scripts must conform to certain guidelines. The following items are affected on the mobile platform: client scripts, UI policies, navigator modules, and UI actions.

Client scripts

For new or existing scripts to be valid for mobile, they must conform to the following requirements:
  • Use the new mobile methods in place of g_form.getControl().
  • Do not use deprecated methods.
  • Do not reference unsupported browser objects.
  • Do not make synchronous JavaScript, GlideAjax, and GlideRecord calls.
  • Do not call methods that are not available for mobile.
  • Enable scripts to run on the mobile UI.
Table 1. Requirements
Use the new mobile methods Several new methods are available for modifying form fields instead of directly manipulating the HTML. These methods replace previous usages of g_form.getControl(), which is deprecated for the mobile platform. In your existing scripts, ensure that the new methods are used in place of methods that are not valid on the mobile platform. For information on these new methods, refer to Mobile GlideForm() API.

See the JavaScript API for API information.

Do not use deprecated methods

The following methods have been deprecated for the mobile platform because direct access to HTML elements is not allowed:

  • g_form.getControl()
  • g_form.getFormElement()
  • g_form.getElement()

To ensure that existing scripts are compatible, remove all calls to deprecated methods from your code. For new scripts, do not use deprecated methods if you want the script to be valid for mobile.

For g_form.getControl(), some of the functionality previously included with this method has been extracted to individual methods. Instead of g_form.getControl(), use the new methods described on the developer site.

See the JavaScript API for API information.

Do not reference unsupported browser objects

The following browser objects are not supported in mobile scripts:

  • Window
  • jQuery or Prototype ($, $j, or $$)
  • Document

Make sure that new scripts do not use these objects, and remove any usage of these objects from your existing scripts. Use GlideForm (g_form) instead, which provides methods such as setLabel(), addDecoration(), and hasField() for accomplishing the same tasks.

Do not make synchronous JavaScript calls

The mobile platform does not allow synchronous JavaScript calls. The g_form.getReference() method must now have the callback parameter defined. For example:

 g_form.getReference(fieldName, callback)

Be sure that all g_form.getReference() calls include the callback parameter. For example, the following script does not include a callback and is incompatible with the mobile platform:

 var userName = g_form.getReference('assigned_to').user_name;
 g_form.setValue('u_assigned_user_name', userName);

The following script has been updated to include the callback and is compatible with the mobile platform:

 g_form.getReference('assigned_to', function(gr) {
     g_form.setValue('u_assigned_user_name', gr.user_name);
 });
Do not make synchronous Ajax calls The mobile platform does not allow synchronous GlideAjax calls. Any use of getXMLWait() in a GlideAjax call will not work on the mobile platform. Be sure that all GlideAjax calls are asynchronous. For more on synchronous versus asynchronous GlideAjax calls and getXMLWait(), see AJAX. For information on the available GlideAjax methods, refer to the GlideAjax. For information on the available GlideAjax methods, refer to the GlideAjax API.
Do not make synchronous GlideRecord calls

The mobile platform does not allow synchronous GlideRecord calls. Make sure that any existing GlideRecord calls include a callback. For example, the following script does not include a callback and is incompatible with the mobile platform:

 var gr = new GlideRecord('incident');
 gr.addQuery('number', g_form.getValue('related_incident'));
 gr.query();
 gr.next();
 g_form.setValue('u_related_incident_description', gr.short_description);

The following script has been updated to include the callback, and is compatible with the mobile platform:

 var gr = new GlideRecord('incident');
 gr.addQuery('number', g_form.getValue('related_incident'));
 gr.query(function(gr) {
     gr.next();
     g_form.setValue('u_related_incident_description', gr.short_description);
 });
Do not use methods unavailable on the mobile platform
Due to the limitations and reduced functionality that is imposed by the mobile platform, the following methods are not deprecated but are not available on the mobile platform. If these run on the mobile platform, no action occurs:
  • showRelatedList ()
  • hideRelatedList ()
  • showRelatedLists ()
  • hideRelatedLists()
  • flash()
  • getSections()
  • enableAttachments()
  • disableAttachments()
  • setReadonly() (Note that setReadOnly() is available)
  • getParameter()
Enable scripts for mobile

Scripts must be enabled for the mobile platform. See Enable client scripts for the mobile browser.

UI policies

A field is now available on the UI Policy form for scripts to run on a desktop or mobile platform, or both at the same time. Update existing policies so that they apply to either the mobile platform or both. For new scripts, also ensure that the mobile option or both is selected. For more on UI policies for mobile, see Enable UI policies for the mobile browser.

Navigator modules

For existing code, modules must be transferred to either the sys_ui_application or sys_ui_module tables to be available on the mobile platform. When developing new code, be sure that all modules are created in the sys_ui_application or sys_ui_module tables. For more information, see Configure the mobile navigator.

UI actions

UI actions must be transferred to the sys_ui_ng_action table to appear on the mobile platform. UI action scripts that do not use deprecated methods do not require changes to the script itself. For new UI actions, be sure that they are created in the sys_ui_ng_action table. For more information, see Mobile interface UI actions.