robdemarco
ServiceNow Employee
ServiceNow Employee
 
During a recent engagement, I was looking for a way to determine within a catalog client script whether the user was accessing the item from the desktop or the Now Mobile app.  We had surfaced info in an HTML field, but that field type doesn't render correctly on mobile yet so we wanted to hide it there. In doing some digging on community, I noticed elements of the solution, but no one-page how-to, so I'm consolidating here.  
 
 
Details:
  • The catalog item itself doesn't make the distinction between Desktop and the Now Mobile app - it treats both as the same (Desktop Only = Desktop and the Now Mobile App)
  • find_real_file.png
  • The function to return true/false is located on the server side in the GlideSystem API (gs.isMobile())
  • We need to use GlideAjax in order to bridge the front end and back end- you can see the script include / catalog client script source code below.
  • Either add your show/hide logic in the onLoad() script where indicated, or use g_scratchpad elsewhere in onChange scripts.
  • Working with Quebec, but this should apply to earlier releases as well

Source:

 
(Client Callable Script Include)

var determine_if_mobile = Class.create();
determine_if_mobile.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    am_i_mobile: function(){
        return gs.isMobile();
    },
    type: 'determine_if_mobile'
});

(Catalog Client Script)

function onLoad() {
    //makes a glideAjax call to find out if we're in the mobile app
    
    var ga = new GlideAjax('determine_if_mobile');
    ga.addParam('sysparm_name', 'am_i_mobile');
    ga.getXML(parseMyResponse);
  
    function parseMyResponse(serverResponse) {
        var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
        if (answer=='false') {
            g_scratchpad.mobileapp = false;
// add show/hide logic here
        }
        else {
            g_scratchpad.mobileapp = true;
// add show/hide logic here
        }
    }
}

 

(Code provided without warranty and was used for demo purposes only - add error handling and be sure to test thoroughly)

 
Comments
Steven Parker
Giga Sage

I know this is old, but I am seeing an issue on Task where the Variables, which have no data, do not show on the Catalog Task in the Agent app.  Out of the box, it shows the "requested item variables", but I have changed that to just "variables" since that screen is on the catalog task table.  Well...it will show variables that have data in them, but not variables with no data (including mandatory fields which are blank on the task).  

 

How can you get a catalog task in the mobile agent app to show the variables in the same way that you can see them in the instance in your browser?  Looks great in the browser, but in the mobile app...Task do not look the same with variables missing when they aren't populated with data.

Version history
Last update:
‎03-05-2021 05:22 AM
Updated by: