The CreatorCon Call for Content is officially open! Get started here.

How can i validate if the emails are valid or not

Emp 53
Tera Contributor

Hi,

Below is my requirement.

if user enter data in multiline text is  - abc@gmail.com,efg@gmail.com,abc@yahoo.com

before creating the RITM i need to validate the emails available in user table or not.

if not i need to display error related to the count of how many of them not correct and what are the email's are wrong.

3 REPLIES 3

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Emp 53 ,

How are you going to enter email ID on multiline text ? Is it one at a time or many at a time by comma separated ?


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

many at a time

create onchange catalog client script as below: select proper catalog, field name and ui type 

GunjanKiratkar_0-1669301107568.png

 

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

    //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('getCallerDetails'); //Scriptinclude
    ga.addParam('sysparm_name', 'getDetails'); //Method
    ga.addParam('sysparm_email', newValue); //Parameters
    ga.getXML(getResponse);

    function getResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		
		alert("Email ID's Already Present :"+answer);
     
    }
}

 

Script Include :-

GunjanKiratkar_1-1669301162524.png

var getCallerDetails = Class.create();
getCallerDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getDetails: function() {
        var currentEmail = this.getParameter('sysparm_email');
        var arr = currentEmail.split(',');
        var alreadyPresent = [];
        for (var i = 0; i < arr.length; i++) {
            var gr = new GlideRecord('sys_user');
            gr.addQuery('email', arr[i]);
            gr.query();
            if (gr.next()) {
                alreadyPresent.push(gr.email).toString();
            }
        }
		return alreadyPresent.toString();
		//return alreadyPresent;

    },


    type: 'getCallerDetails'
});

 

 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy