Client Script (UI Type: All) not working in Mobile Agent app
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10 hours ago
Hi,
I have a requirement in ServiceNow Agent Mobile.
We have a field called Barcode (asset_tag) on the x_map_eam_devices table, and it needs to be unique.
I have a Script Include and Client Script to check if the barcode already exists.
The script works fine on the desktop form, but it doesn’t work in the Mobile App, Is there any fix for this?
UI Type is set to All, Script is in Workplace scope and Mobile app is in Technician app scope
We use both the Edit Asset and Create New Asset functions in the mobile app.
There is also an onSubmit Client Script on the same table.
Here’s the onChange Client Script I’m using:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Check for duplicate barcode
var gaDevice = new GlideAjax('FacilitiesAssetClientUtils');
gaDevice.addParam('sysparm_name', 'checkDuplicateBarcode');
gaDevice.addParam('sysparm_barcode', newValue);
gaDevice.getXML(validateBarcode);
}
function validateBarcode(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
alert('This barcode is already in use');
g_form.clearValue('asset_tag');
}
}
Script Include
var FacilitiesAssetClientUtils = Class.create();
FacilitiesAssetClientUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkDuplicateBarcode: function() {
var grDevice = new GlideRecord('x_map_eam_devices');
grDevice.addQuery('asset_tag', this.getParameter('sysparm_barcode'));
grDevice.query();
if (grDevice.hasNext())
return true;
else
return false;
},
type: 'FacilitiesAssetClientUtils'
});