Difference between client scripts & catalog client scripts re: calling script includes?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 02:28 PM
So, I plagiarised the script include + client script to retrieve a user's e-mail address and populating a field (string, single-line text) with the retrieved e-mail address. They worked in the form view, but they didn't work in the record producer.
Since I merely copied and pasted the codes from the client script to the catalogue client script, something must have changed somewhere to make the catalogue client script not work. Would anyone happen to have any clues?
Thank you in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 02:39 PM
Ideally, it should work. Please make sure to update the script to include the Record producer variable name and include a few alert messages to see which script line is exactly not working.
- Pradeep Sharma

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 05:57 PM
Hi Cédric,
Works OK for me. I'm using the same Script Include in both Catalog Item and Record Producer.
Script Include
var UserUtil = Class.create();
UserUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserEmail: function () {
var userSysId = this.getParameter('sysparm_user_sys_id');
var grUser = new GlideRecord('sys_user');
if (grUser.get(userSysId)) {
return grUser.getValue('email');
}
},
type: 'UserUtil'
});
1. Catalog Item
Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('UserUtil');
ajax.addParam('sysparm_name', 'getUserEmail');
ajax.addParam('sysparm_user_sys_id', newValue);
ajax.getXMLAnswer(function(answer) {
if (answer.length > 0) {
g_form.setValue('email', answer);
}
});
}
Execution result
2. Record producer
Client script content is the same as catalog item
Execution result

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 06:29 PM
Hi again,
As I've replied in the other thread, is they all in the same scope?
If they are in different scopes, Script Include should have "Accessible from" set to "All application scopes" and client script should specify script include using prefix "global."
e.g.
var ajax = new GlideAjax('global.GetUserDepartment');