Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Issue with client script on CSM Workspace

Community Alums
Not applicable

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
Kilo Sage
Kilo Sage

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

 

Community Alums
Not applicable

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.