How can I determine if the email ID is present in the group member record?

shareef_223
Tera Contributor

I have a requirement involving two variables: "Email ID" and "Type of Access." The "Type of Access" variable is a reference field linked to the group table.

Here's the scenario: When a user enters their email ID and selects a type of access, the system needs to check if the email is already associated with any group or user records. If the email is found within the group or user records, it should trigger an alert message stating, "You are already present in the group. Please select another group." If the email is not found, the system should proceed to create a request.

Could anyone assist me with this?

6 REPLIES 6

Hi @Chetan Mahajan, I tried with this but still it's not working.

Onkar Pandav
Tera Guru

@shareef_223 ,

Try below code

 

Client Script:
onChange client script

Field name : Email Id

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ga = new GlideAjax('SE_Validationcheckforemail');
    ga.addParam('sysparm_name', 'validateEmail');
    ga.addParam('sysparm_email', newValue);
    ga.getXMLAnswer(response);
 
    function response(answer) {
       if (answer == 'true') {
            g_form.showFieldMsg('type_of_access', "EMAIL ALREADY EXIST",'error');
    }
}
}

 

Script Include:
Client callable = True

var SE_Validationcheckforemail = Class.create();
SE_Validationcheckforemail.prototype = Object.extendsObject(AbstractAjaxProcessor, {    
 
validateEmail:function(){
var mail = this.getParameter('sysparm_email'); // get email value from client script
var emailGr = new GlideRecord('sys_user');
emailGr.addQuery('email', mail);
emailGr.query();
if(emailGr.hasNext())
        return 'true';
else
        return 'false'; 
},
type: 'SE_Validationcheckforemail',
});