How can I determine if the email ID is present in the group member record?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 04:09 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 04:14 AM
Hi,
I had answered on one similar type of requirement. Please check below link.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 04:18 AM - edited ‎04-04-2024 04:21 AM
Hello @shareef_223 ,
Create an OnChange Client Script on a table to trigger a Script Include using GlideAjax. Validate whether the provided email ID is associated with other groups or users. Ensure that the Script Include is configured as Client Callable.
// Client Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var emailId = g_form.getValue('email_id'); // Change value with your field name
var typeOfAccess = g_form.getValue('type_of_access'); // Change value with your field name
if (emailId && typeOfAccess) {
var ga = new GlideAjax('CheckEmailAndGroup'); // Script include Name
ga.addParam('sysparm_name', 'checkEmailAndGroup'); // Function Name
ga.addParam('sysparm_emailId', emailId); // Parameter to pass
ga.addParam('sysparm_groupSysId', typeOfAccess); // Parameter to pass
ga.getXML(handleResponse); // Callback Function
}
}
function handleResponse(response) {
var result = response.responseXML.documentElement.getAttribute('answer');
if (result === 'present') {
alert('This email id is already associated with other Group or User .');
} else {
// Proceed with request creation or any other action
}
}
Script include : (Client callable)
var CheckEmailAndGroup = Class.create();
CheckEmailAndGroup.prototype = {
initialize: function() {},
checkEmailAndGroup: function(emailId, groupSysId) {
// Check if the email is associated with any group records
var groupGr = new GlideRecord('sys_user_grmembers');
groupGr.addQuery('email', emailId);
groupGr.addQuery('group', groupSysId);
groupGr.query();
if (groupGr.hasNext()) {
return 'present';
}
// Check if the email is associated with any user records
var userGr = new GlideRecord('sys_user');
userGr.addQuery('email', emailId);
userGr.query();
if (userGr.hasNext()) {
return 'present';
}
return 'not_present';
},
type: 'CheckEmailAndGroup'
};
Kindly mark correct and helpful if applicable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 04:47 AM
Hi @Chetan Mahajan ,
Thanks for the reply, I tried this but it is not working as expected. when i select a client callable in the script include, it is showing the following systax
var CheckEmailAndGroup = Class.create(); CheckEmailAndGroup.prototype = { initialize: function() {},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2024 04:51 AM