- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 09:19 PM
Hi Team,
I have a reference variable (mobile_device) on the service portal and when a device is selected two fields appear (IMEI & Serial Number). It is hidden until mobile_device field is not empty. The mobile device details (u_imei and serial_number) are stored in the (u_cmdb_ci_mobile_device). I have written up a script include and called it from a catalog client script. It does not seem to work and i am not sure what the error is. I know it is something to do with the code but i am not too sure what is causing the issue. The screenshots are below.
All help is appreciated.
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 05:46 PM
Hi Thiraj,
Hope this helps:
Server Script:
var getDeviceCIDetails = Class.create();
getDeviceCIDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIDevice: function() {
var obj = {};
var json = new JSON();
var mob = this.getParameter('sysparm_mob');
var mobDets = new GlideRecord('u_cmdb_ci_mobile_device');
mobDets.addQuery('sys_id', mob);
mobDets.query();
if(mobDets.next() && gs.getUser()) {
obj.imei = mobDets.u_imei + '';
obj.serial_number = mobDets.serial_number + '';
return json.encode(obj);
}
},
type: 'getDeviceCIDetails'
}
);
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if(newValue == oldValue) {
return;
}
var gaj = new GlideAjax('getDeviceCIDetails');
gaj.addParam('sysparm_name', 'getCIDevice');
gaj.addParam('sysparm_mob', newValue);
gaj.getXML(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//check that answer is not nil before continuing
if(answer) {
var answer_json = answer.evalJSON();
g_form.setValue('imei', answer_json.imei);
g_form.setValue('serial', answer_json.serial_number);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 06:04 PM
Hi Cam,
I gave it a try but does not seem to work. The two fields (IMEI & Serial number) does not get populated. I rechecked if this particular device has a IMEI and Serial Number in the back end and it does. The table referenced is also correct. I just cannot seem to find what is causing this error. The code looks correct as well.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 06:52 PM
Hi Thiraj,
Can you confirm that the variables in the Catalog Item are named "imei" and "serial"?
I think the next step would be to do some logging, place some gs.info() statements in your script include and check the logs in ServiceNow to see that it's running as expected and it's setting the values as expected.
Place some alert() statements in your client script and see where it is failing. E.g what does the answer variable look like after it has been set. What does it look like after it has been evaluated as a JSON object?
alert(answer.toString());
alert(answer_json.imei);
alert(answer_json.serial_number);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 07:29 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 07:36 PM
Place an alert(newValue); on the client script before the GlideAjax initialisation.
Is this firing? Are you seeing a value resembling a sys_id?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 07:37 PM
Hi Cam,
It is not firing!
Thank you