My client script is not executing. Any error message or info message also not showing up

srinivasrao
Tera Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage("I am in ");
g_form.addErrorMessage (" i am here ");
function concatenateCallerIdAndStorename(callerID) {
// Perform an asynchronous GlideAjax call to fetch user details
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getDetails'); // Correct function name in script include
ga.addParam('sys_id', callerID);
ga.getXMLAnswer(function(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
var userDetails = JSON.parse(answer);
var concatenatedValue = userDetails.user_id + " - " + userDetails.u_store_name;
 
// Set the concatenated value in a custom field (e.g., u_caller_details)
g_form.setValue('u_caller_details', concatenatedValue);
}
});
}
 
// Call the function to concatenate caller ID and department
concatenateCallerIdAndStorename(newValue);
}
 
-------------------------------
Script Include:
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getDetails: function() {
var sys_id = this.getParameter('sys_id');
var user = new GlideRecord('sys_user');
user.get(sys_id);

var details = {
user_id: user.user_name.toString(),
u_store_name : user.u_store_name.getDisplayValue().toString()
};

return JSON.stringify(details);
}


});
7 REPLIES 7

Community Alums
Not applicable

Hi @srinivasrao ,

please make update in the client as ss. 

polnilesh99_0-1722576131499.png

 

please accept as solution and helpful, if this will solve the issue.

Deepak Shaerma
Kilo Sage

Hi @srinivasrao 

if you are using getReferenceValue in scriptinclude for reference fields, dont use to string

Quinten
Tera Guru

try putting the keyword "debugger"; somewhere at the top of your client script. Save it, after that, try executing the client script by meeting the conditions. If your client script is running, your browser will be paused.

WARNING: don't put this code in a production environment, it will pause for everyone.

If the client script in fact doesn't execute, make sure to double check if the conditions of your onChange client scripts are actually met.

This.

Note: You need to open the browser console, otherwise the breakpoint (which is what the debugger statement sets) won't be triggered.

 

Also please check if you have the script active for all environments, or just for one particular:

MarkusKraus_0-1722596339204.png