- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 07:27 AM
Hi,
I have a requirement to show the cost center in the catalog form from the custom table.
In the custom table we have only user id.
On change of user id in the form cost center should populate.
Script include:
var requestor_details = Class.create();
requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserDetailsInternal: function() {
var userName = this.getParameter('sysparm_user');
var result = "";
var costing = new GlideRecord("u_custom_user");
costing.addEncodedQuery('u_useridISNOTEMPTY');
costing.query();
if (costing.next()) {
var cost = costing.u_userid;
var user = new GlideRecord('sys_user');
user.addQuery('user_name', cost);
user.query();
while (user.next()) {
result = user.cost_center.getDisplayValue();
}
}
return JSON.stringify(result);
},
type: 'requestor_details'
});
Client script:
var user_id = g_form.getValue('requested');
var ga = new GlideAjax('requestor_details');
ga.addParam('sysparm_name', 'getUserDetailsInternal');
ga.addParam('sysparm_user', user_id);
ga.getXML(EmployeeDetailsLookup);
}
function EmployeeDetailsLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
alert(result);
g_form.setValue('cost', result);
}
Please help in this.
Thank you!
Samiksha
Solved! Go to Solution.
- Labels:
-
Request Management
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 07:38 AM
The problem appears to be in your script include. You are doing a search against your custom table but your query is only if u_user_id is not empty. I would think you just need to use the andQuery('u_user_id', userName).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 07:38 AM
The problem appears to be in your script include. You are doing a search against your custom table but your query is only if u_user_id is not empty. I would think you just need to use the andQuery('u_user_id', userName).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2023 07:45 AM
Hi Brian,
Yes, you are right. It is working fine.
Thank you.