
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2023 03:58 AM
I've a CI form where there is a field called Group Email. I wanted to have a validation where this field should accept only valid DL no other text nor individual email id. It should only accept valid DL.
How to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 03:44 AM
@Bijay Kumar Sha For this requirement you need t o create client callable script include to get all the group email ID's and compare it with group email from CI form. Then write glideAjax logic to call that script include in OnChange client script.
Script Include -
Name - getGroupEmailIDs
Client callable = Checked
Put below script in script section -
var getGroupEmailIDs = Class.create();
getGroupEmailIDs.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmailList: function() {
var groupEmailList = [];
var matchFound = '';
var groupEmail = this.getParameter('sysparm_groupEmail');
var grGroup = new GlideRecord('sys_user_group');
grGroup.addActiveQuery();
grGroup.query();
while (grGroup.next()) {
if (grGroup.email)
groupEmailList.push(grGroup.email.toString());
}
if (groupEmailList.length > 0) {
for (var i = 0; i < groupEmailList.length; i++) {
if (groupEmailList[i].toString().toUpperCase() == groupEmail.toUpperCase())
matchFound = 'Yes';
}
}
if (!matchFound)
matchFound = 'No';
return matchFound;
},
type: 'getGroupEmailIDs'
});
onChange client script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var getGroupEmailList = new GlideAjax('global.getGroupEmailIDs');
getGroupEmailList.addParam('sysparm_name', 'getEmailList');
getGroupEmailList.addParam('sysparm_groupEmail', newValue)
getGroupEmailList.getXMLAnswer(function(output) {
if (output == 'No') {
g_form.setValue('u_group_email', '');
g_form.showFieldMsg('u_group_email', 'Please enter a valid DL email address', 'error');
} else {
g_form.clearMessages('u_group_email');
}
});
}
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 11:15 PM
@Bijay Kumar Sha have you tried my solution ? it worked ?
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 02:41 AM
@Bijay Kumar Sha have you tried my solution ? it worked ?
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 01:38 AM
@Bijay Kumar Sha If you want exact DL match then you need to hardcode the email id's in script or use system property to store it. Use below script and test it.
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//var regExp = /^(KID|kid){1}([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/;
var regExp = /KID-SPINEProductTeam@kid.com/i;
if (!regExp.test(newValue)) {
g_form.setValue('u_group_email', '');
g_form.showFieldMsg('u_group_email', 'Please enter a valid DL email address', 'error');
}
else{
g_form.clearMessages('u_group_email');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 01:52 AM - edited 07-20-2023 02:09 AM
@SANDEEP28 I think this code will validate only one email ID i.e 'KID-SPINEProductTeam@kid.com'. But there are 1000s of Email IDs of 1000s of groups exist. How I can validate that dynamically. In future also new group will get created and new DL will also get created. Some existing group might also get deactivated so DL also.
Hope you get it.