Issue with client script on CSM Workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2025 12:01 AM - edited ‎05-27-2025 12:24 AM
The below client script is working on the Platform/Native view but not on the CSM/FSM workspace. It is working for the GlideAjax function but not for the other 2 validations as it shows the message for a split second and then disappears .
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue !== newValue.trim()) {
g_form.clearValue('u_email');
g_form.showFieldMsg('u_email', 'Email contains space at the beginning or end.', 'error');
return;
}
var pattern = new RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
if (newValue && !pattern.test(newValue)) {
g_form.setValue('u_email', '');
g_form.showFieldMsg('u_email', 'Invalid email address.', 'error');
return;
}
var ga = new GlideAjax('CSMCustomUtils');
ga.addParam('sysparm_name', 'validatContactEmailAddress');
ga.addParam('sysparm_email', newValue);
ga.getXML(function(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer === 'true') {
g_form.clearValue('u_email');
g_form.showFieldMsg('u_email', 'Contact already exist.', 'error');
}
});
}
The UI Type is already set as 'All' and Isolate Script is 'true'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2025 12:04 AM
@Amit Giri Client scripts interact with fields on the form. If the fields your script is accessing are hidden within the workspace's details tab, the script might not be able to find them.
Try adding an alert() statement at the beginning of the script to see if it triggers and check the value of your script variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2025 12:17 AM
Hello @Nilesh Pol ,
The fields are accessible within the workspaces. The script is not working for the first 2 validations, trim() and regex, but is working for the GlideAjax validation and the message stays for this instance. For the other 2, it is disappearing as soon as it shows up.
Thank you.