- 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 07:51 PM
Hi Cam,
I got it to work. The code was perfect. The variable set was the issue. I was testing on a catalog item that was not using the same variable set.
Sorry and thank you for your time.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 07:52 PM
That's great!
You're very welcome
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2017 11:39 PM
Create a Json variable in script include.
without that the Json parsing you are doing in client script wont work.
And
the condition If(gs.User()) this will always return true and so controller will enter inside if condition. So this is not achieving anything in specific.
After that change return true to return the json object you have created.