ServiceNow mobile - client script

sarkar_saurav
Kilo Explorer

Is it possible to run Javascript with a UI macro in the ServiceNow mobile view?

5 REPLIES 5

bernyalvarado
Mega Sage

Indeed it's possible and you can use gs.isMobile() to know if you're on a mobile device.



As a reference:


Smartphone detection in UI Page or UI Macro or in Jelly Scripting?


Configuring the Legacy Mobile UI - ServiceNow Wiki



Thanks,


Berny


sarkar_saurav
Kilo Explorer

Thanks Berny,



I should have mentioned it earlier, but my requirement is to run client side javascript on mobile.


Hi Saurav, unfortunately that will not work. To be sure i did a very quick test on my own adding the following code in a UI macro which I ran using the mobile view.



function getValue(){
  return 'SOMETHING';
}
</script>
<input type="text" onClick="this.value = getValue();" />


And when clicked the input textbox 'SOMETHING' is not assigned as the textbox value.



Thanks,


Berny


Malik Raji
Kilo Contributor

ServiceNow's mobile view does not support running JavaScript directly within UI macros. This is primarily due to security restrictions and best practices for mobile application development. ServiceNow's mobile platform is designed to provide a consistent and secure user experience across various devices and operating systems.

Instead of using JavaScript within UI macros, ServiceNow provides specific mobile development capabilities, such as creating mobile-friendly UI components and leveraging ServiceNow's mobile app development framework.

For customizing the mobile view in ServiceNow, you can use ServiceNow's Mobile Studio, which provides a set of tools and features for building and customizing mobile apps within the ServiceNow platform. Mobile Studio allows you to create custom mobile UI components, define mobile-specific behaviors, and design mobile-friendly experiences without the need to directly run JavaScript within UI macros.