Issue with client script on CSM Workspace

Amit Giri
Kilo Guru

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'.

2 REPLIES 2

Nilesh Pol
Tera Guru

@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.

 

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.