I am trying to validate through validation script where I want to have validation first through custom object and if not present then let create new DL or Shared Mail boxes. I am getting error all the time as beanshell error.
can you share the error or your code in which you are getting error?
ValidationScript is generally used to validate the value selected in the form field like constraint violation, however what i understand from your comment, you want a value entered in field to be validated against a custom Object if value is not present in custom object then proceed with operation else return validation message. If so i would request you to share your code and error so that we can try to help you better.
If you’re trying to validate this in the form, you can read the existing custom object data and store it in a Map object. This will allow you to check if it contains the necessary information whenever you need to perform validation, if you plan to validate this data in multiple fields.
If you could share the error message or any code where you are encountering an exception, it would help me guide you more effectively.
If you’re looking for more information about custom object code, here is the link.Leveraging the custom object in IdentityIQ
Let me know how it’s worked!
Thanks,
@SivaLankapalli
Hi Dheeraj,
While trying to create new DL i want to use custom object as a validation before creating new DL
String pattern = "^[a-zA-Z0-9 _\\-\\.]+$";
java.util.regex.Pattern regex = java.util.regex.Pattern.compile(pattern);
java.util.regex.Matcher matcher = regex.matcher(groupName);
if (groupName == null || groupName.length() > 32) {
return "Distribution List Name cannot exceed 32 characters.";
}
if (!matcher.matches()) {
return "Only letters, numbers, space, underscore (_), hyphen (-), and dot (.) are allowed.";
}
sailpoint.object.Custom unifiedMailCustom = context.getObjectByName(sailpoint.object.Custom.class, "CustomMail");
java.util.List distributionLists = sailpoint.tools.Util.listify(unifiedMailCustom.get("Distribution Lists"));
java.util.List sharedMailboxes = sailpoint.tools.Util.listify(unifiedMailCustom.get("Shared Mailboxes"));
java.util.List mailEnabledTeams = sailpoint.tools.Util.listify(unifiedMailCustom.get("Mail Enabled Teams"));
String dlNameLower = groupName.toLowerCase().trim();
boolean exists = false;
for (Object name : distributionLists) {
if (name != null && name.toString().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
if (!exists) {
for (Object name : sharedMailboxes) {
if (name != null && name.toString().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (!exists) {
for (Object name : mailEnabledTeams) {
if (name != null && name.toString().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (exists) {
throw new RuntimeException("Distribution List Name already exists. Please choose another.");
}
return "Distribution List Name is valid.";
</Source>
</ValidationScript>
String pattern = "^[a-zA-Z0-9 _\\-\\.]+$";
java.util.regex.Pattern regex = java.util.regex.Pattern.compile(pattern);
java.util.regex.Matcher matcher = regex.matcher(groupName);
if (groupName == null || groupName.length() > 32) {
return "Distribution List Name cannot exceed 32 characters.";
}
if (!matcher.matches()) {
return "Only letters, numbers, space, underscore (_), hyphen (-), and dot (.) are allowed.";
}
sailpoint.object.Custom unifiedMailCustom = context.getObjectByName(sailpoint.object.Custom.class, "Unified Mail Export Data");
java.util.List distributionLists = sailpoint.tools.Util.listify(unifiedMailCustom.get("Distribution Lists"));
java.util.List sharedMailboxes = sailpoint.tools.Util.listify(unifiedMailCustom.get("Shared Mailboxes"));
java.util.List mailEnabledTeams = sailpoint.tools.Util.listify(unifiedMailCustom.get("Mail Enabled Teams"));
String dlNameLower = groupName.toLowerCase().trim();
boolean exists = false;
for (Object name : distributionLists) {
if (name != null && name.toString().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
if (!exists) {
for (Object name : sharedMailboxes) {
if (name != null && name.toString().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (!exists) {
for (Object name : mailEnabledTeams) {
if (name != null && name.toString().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (exists) {
throw new RuntimeException("Distribution List Name already exists. Please choose another.");
}
return "Distribution List Name is valid.";
</Source>
</ValidationScript>
Hi @Himanshu_singh03 ,
Can you please share error you are getting.
Meanwhile can you please try below code:
if (groupName == null || groupName.length() > 32) {
return "Distribution List Name cannot exceed 32 characters.";
}
groupName = groupName.trim();
String pattern = "^[a-zA-Z0-9 _\\-\\.]+$";
java.util.regex.Pattern regex = java.util.regex.Pattern.compile(pattern);
java.util.regex.Matcher matcher = regex.matcher(groupName);
if (!matcher.matches()) {
return "Only letters, numbers, space, underscore (_), hyphen (-), and dot (.) are allowed.";
}
sailpoint.object.Custom unifiedMailCustom = context.getObjectByName(
sailpoint.object.Custom.class,
"Unified Mail Export Data"
);
List<String> distributionLists = sailpoint.tools.Util.listify(unifiedMailCustom.get("Distribution Lists"));
List<String> sharedMailboxes = sailpoint.tools.Util.listify(unifiedMailCustom.get("Shared Mailboxes"));
List<String> mailEnabledTeams = sailpoint.tools.Util.listify(unifiedMailCustom.get("Mail Enabled Teams"));
String dlNameLower = groupName.toLowerCase();
boolean exists = false;
for (Object name : distributionLists) {
if (name != null && name.toString().trim().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
if (!exists) {
for (Object name : sharedMailboxes) {
if (name != null && name.toString().trim().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (!exists) {
for (Object name : mailEnabledTeams) {
if (name != null && name.toString().trim().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (exists) {
throw new RuntimeException("Distribution List Name already exists. Please choose another.");
}
return "Distribution List Name is valid.";
and let me know in case you are still facing any issue. please handle escape characters.
Also i do not see listify method in sailpoint.tools.Util in javaDoc, not sure if this method is correct. In case custom Object already have list of string in key “Distribution Lists”,“Shared Mailboxes”, Mail Enabled Teams" then i would suggest not user listify. You can direclty use
List<String> distributionLists = (List)unifiedMailCustom.get("Distribution Lists");
List<String> sharedMailboxes = (List)unifiedMailCustom.get("Shared Mailboxes");
List<String> mailEnabledTeams = (List)unifiedMailCustom.get("Mail Enabled Teams");
Updated code:
if (groupName == null || groupName.length() > 32) {
return "Distribution List Name cannot exceed 32 characters.";
}
groupName = groupName.trim();
String pattern = "^[a-zA-Z0-9 _\\-\\.]+$";
java.util.regex.Pattern regex = java.util.regex.Pattern.compile(pattern);
java.util.regex.Matcher matcher = regex.matcher(groupName);
if (!matcher.matches()) {
return "Only letters, numbers, space, underscore (_), hyphen (-), and dot (.) are allowed.";
}
sailpoint.object.Custom unifiedMailCustom = context.getObjectByName(
sailpoint.object.Custom.class,
"Unified Mail Export Data"
);
List<String> distributionLists = (List)(unifiedMailCustom.get("Distribution Lists"));
List<String> sharedMailboxes = (List)(unifiedMailCustom.get("Shared Mailboxes"));
List<String> mailEnabledTeams = (List)(unifiedMailCustom.get("Mail Enabled Teams"));
String dlNameLower = groupName.toLowerCase();
boolean exists = false;
for (Object name : distributionLists) {
if (name != null && name.toString().trim().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
if (!exists) {
for (Object name : sharedMailboxes) {
if (name != null && name.toString().trim().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (!exists) {
for (Object name : mailEnabledTeams) {
if (name != null && name.toString().trim().toLowerCase().equals(dlNameLower)) {
exists = true;
break;
}
}
}
if (exists) {
throw new RuntimeException("Distribution List Name already exists. Please choose another.");
}
return "Distribution List Name is valid.";
For anything I select I am getting : "Only letters, numbers, space, underscore (_), hyphen (-), and dot (.) are allowed.
can you share me the custom object you are using so that i can test it in my local?
This could only give “Only letters, numbers, space, underscore (_), hyphen (-), and dot (.) are allowed” for every input only if the matcher fails, possible reason could be.
Invisible or Invalid Characters
- Your input may contain hidden characters, such as:
- Non-breaking spaces (
\u00A0
) - Smart quotes or special punctuation
- Unicode characters (like emojis or non-English letters)
- Non-breaking spaces (
groupName.trim()
only removes regular whitespace, not these characters.
Before the regex match, add:
log.error("Input groupName: '" + groupName + "'");
for (char c : groupName.toCharArray()) {
log.error("Char: '" + c + "' - ASCII: " + (int)c);
}
This will show you exactly what characters are in the input, even if they’re not visible.
I tried but again getting error
Hi @Himanshu_singh03 ,
What is the error you are getting.
straighaway it is not handling the name and i am getting
can you please share me the custom objects so that i can test it on my local?