Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Script needed

Saib1
Tera Guru

Hi all,

 

I need a script for the below requirement

 

we have the field called queue owner email id , if we type without '@' it should give alert "Incorrect format. please enter xxx@xxx.com". During onchange i need to validate it.

Saib1_0-1730217600548.png

 

3 REPLIES 3

Runjay Patel
Giga Sage

Hi @Saib1 ,

 

You can use below script if you only want to check text contains @ or not. Writing onchange client script.

if (!newValue.includes('@')) {
        g_form.addErrorMessage('Incorrect format. Please enter xxx@xxx.com');
           }

 

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Luiz Lucena
Mega Sage

We did something similar, but the contrary, in our case, we don't want them to add the "@domain.com" because we added some automation behind. 

Here is an example, already modified to your case, you will create a Catalog Client Script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var regex = /@/;
    if (!regex.test(newValue)) {
        getMessage('Incorrect format. Please enter xxx@xxx.com.',function(msg){
			alert(msg);});
			
        g_form.clearValue('queue_owner_name');
    }
}

LuizLucena_0-1730218804634.png

 

Hitoshi Ozawa
Giga Sage
Giga Sage

@Saib1 Why not just specify validation Regex to be "Email"?

HitoshiOzawa_0-1730246691353.png

Execution result:

HitoshiOzawa_1-1730246721748.png

 

If you want to change the error message, go to "Service Catalog" - "Catalog Variables" - "Variable Validation Regex".

Select Email and change text in "Validation message"

HitoshiOzawa_2-1730246816342.png