- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 06:02 AM
Hi Community,
I hope you doing well, we have a client script that is auto populating asset details using script include as shown below. here the problem we are facing is when we are changing the username who is having asset details it is getting populating but when we are changing the username who don't have assets, we are facing problem, and it is showing
this error(Error There is a JavaScript error in your browser console). Please can someone please help me on this. thanks in advance.
Here is the Script include:
Client script:
1) The person having asset details (Mohamed Cheikhrouhou)
2) These are the asset details
3) The person doesn't having asset details (Rajesh kongamudi) here it is showing console error
4) Not making those assett details empty and keeping the same assett details having the previous person asset details
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 06:13 AM - edited 09-25-2023 06:15 AM
Hi @rajeshKongamudi ,
Try changing your script include to the script below, and try. The error is because of returning a variable which is not defined if the user have no asset.
var getassetsforusers = Class.create();
getassetsforusers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
findUserswithMoreThan1Assets: function() {
//var arr = [];
var id = this.getParameter('sysparm_userID');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', id);
user.query();
var asset = '';
if(user.next()){
var aseetList = new GlideRecord('cmdb_ci_computer');
aseetList.addQuery('assigned_to', user.sys_id);
aseetList.addQuery('install_status', '1');
aseetList.addQuery('operational_status', '1');
aseetList.orderByDesc('u_last_check_in');
aseetList.query();
if(aseetList.next()){
asset = aseetList.asset_tag+ ',' +aseetList.serial_number+ ',' +aseetList.model_id.getDisplayValue()+ ',' +aseetList.name;
//var assetname = ;
}
}
return asset;
},
type: 'getassetsforusers'
});
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 06:13 AM - edited 09-25-2023 06:15 AM
Hi @rajeshKongamudi ,
Try changing your script include to the script below, and try. The error is because of returning a variable which is not defined if the user have no asset.
var getassetsforusers = Class.create();
getassetsforusers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
findUserswithMoreThan1Assets: function() {
//var arr = [];
var id = this.getParameter('sysparm_userID');
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', id);
user.query();
var asset = '';
if(user.next()){
var aseetList = new GlideRecord('cmdb_ci_computer');
aseetList.addQuery('assigned_to', user.sys_id);
aseetList.addQuery('install_status', '1');
aseetList.addQuery('operational_status', '1');
aseetList.orderByDesc('u_last_check_in');
aseetList.query();
if(aseetList.next()){
asset = aseetList.asset_tag+ ',' +aseetList.serial_number+ ',' +aseetList.model_id.getDisplayValue()+ ',' +aseetList.name;
//var assetname = ;
}
}
return asset;
},
type: 'getassetsforusers'
});
Please mark my answer helpful and accept as solution if it helped you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2023 07:33 AM