error when trying to use client callable script include.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 03:51 AM
Hi,
My requirement is when the caller field changes in the incident table, user created email field should reflect the caller's email id. I am trying to do this using client callable script include. I am getting an error as shown in the second image. is there anything wrong in the code i have written. Please help me to rectify the error.(bottom most image is the clientscript.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:35 AM
Ensure you have only one Script Include with this name. Add a gs.info line as the first line inside the getEmail to confirm the Script Include is running, then at the end to confirm a value is returned. It's best practice to always return something from a SI to prevent unexpected results, so try something like var answer = 'false'; at the beginning, then set answer = gr.email.toString(); in the gr if block, return answer; at the end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:53 AM
Hi @SarubalaC ,
update the script include make sure it return something
var updateCallerEmail = Class.create();
updateCallerEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmail: function() {
var userId = this.getParameter('sysparm_callerid');
if (!userId) return '';
var userGR = new GlideRecord('sys_user');
if (userGR.get(userId)) {
return userGR.getValue('email');
}
return '';
}
});
Client script
getXMLAnswer is easy to use I prefer it
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue == '') {
g_form.setValue('u_email', '');
return;
}
var ga = new GlideAjax('updateCallerEmail');
ga.addParam('sysparm_name', 'getEmail');
ga.addParam('sysparm_callerid', newValue);
ga.getXMLAnswer(function(response) {
g_form.setValue('u_email', response);
});
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 07:57 AM
you can use onChange with getReference() callback and no GlideAjax, Script Include is required.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('u_email');
}
var ref = g_form.getReference('caller_id', callBackMethod);
}
function callBackMethod(ref) {
if (ref.email)
g_form.setValue('u_email', ref.email);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 08:27 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader