Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Mobile UI Rules

AnanyaN77332247
Tera Contributor

Client Scripts Not Working in Mobile? Use Mobile UI Rules Instead

 

While working on the Incident Edit screen in Mobile, I encountered an unexpected behaviour. I had added the following fields to the mobile form:

  • Business Service
  • Service Offering

Expected Behaviour :

In the Desktop (Native UI):

  1. Select a Business Service
  2. Select a related Service Offering
  3. Change the Business Service

The Service Offering should be cleared automatically if it no longer belongs to the selected Service.

This behaviour was already handled by an existing Client Script.

Issue in Mobile                                                                                                                                                                                        

In the Mobile App:

  • I selected a Service
  • Selected a valid Service Offering
  • Then changed the Service

However, the Service Offering was not cleared.

Root Cause

After analysing the issue, I realized that the logic was implemented using a Client Script (g_form), which does not execute in Mobile.

The Mobile framework does not support:

  • g_form
  • g_scratchpad
  • Client-side GlideRecord
  • Traditional Client Scripts

As a result, even though the logic existed, it was never executed in Mobile.

Solution Approach

This led me to explore Mobile UI Rules, which are specifically designed for handling dynamic behaviour in mobile applications.

To resolve the issue, I reimplemented the logic using:

  • Mobile UI Rule
  • Run Client Script (Mobile)
  • Mobile Callable Script Include

Implementation

Step 1: Create Mobile UI Rule

Navigate to:
System Mobile → Mobile UI → Mobile UI Rules

Configure the following:

  • Name: Clear Service Offering on change of Service
  • Parent Table: Parameter Screen
  • Parent: Input form screen: Edit
  • Trigger: onChange
  • Condition:
    business_serviceVALCHANGES


Step 2: Add UI Rule Action

  • Operation: Run Client Script
  • Application: ITSM Mobile Agent


Step 3: Add Client Script in UI Rule Action

Add the following script in the Client Script field:

function onChange(inputName, newValue) {

 

    if (inputName !== "business_service") {

        return;

    }

 

    m_form.setAffectedInputs(["service_offering"]);

 

    var selectedService = m_form.getValue("business_service");

    var offering = m_form.getValue("service_offering");

 

    if (!selectedService || !offering) {

        return;

    }

 

    var caller = new MobileScriptIncludeCaller(

        "global.MobileCallable",

        "checkOfferingParent"

    );

 

    caller.addParam("offering", offering);

 

    caller.call(function(parentSysId) {

 

        if (!parentSysId || parentSysId !== selectedService) {

 

            m_form.setValue("service_offering", "");

 

            m_form.addInfoMessage(

                "The selected Service Offering does not belong to the chosen Service."

            );

        }

    });

}



Step 4: Mobile Callable Script Include

 

var MobileCallable = Class.create();

MobileCallable.prototype = Object.extendsObject(AbstractMobileCallableInclude, {

 

    checkOfferingParent: function() {

 

        var offering = this.getParameter("offering");

 

        var gr = new GlideRecord("service_offering");

 

        if (gr.get(offering)) {

            return gr.getValue("parent");

        }

 

        return "";

    },

 

    type: 'MobileCallable'

});

Ensure that the Script Include is marked as Mobile Callable.

Understanding m_form and Mobile Callable Script Include :

In Mobile UI Rules, m_form replaces g_form and is used to interact with form fields.
Common methods include:

  • getValue() – get field value
  • setValue() – set field value
  • setAffectedInputs() – define impacted fields
  • addInfoMessage() – show messages

Mobile scripts do not support server-side APIs like GlideRecord or even methods like getReference().
To handle server-side logic, Mobile Callable Script Includes are used. These extend AbstractMobileCallableInclude and return data to the client.

They are invoked using MobileScriptIncludeCaller, which allows the mobile script to pass parameters and asynchronously receive a response from the server.

After implementing Mobile UI Rules, the Service Offering correctly clears when the Business Service is changed, ensuring consistency with the Desktop experience and maintaining data integrity. This highlights that Client Scripts using g_form do not work in Mobile and must be redesigned using mobile-specific approaches such as Mobile UI Rules.

 

0 REPLIES 0