<Field displayName="Application Name" dynamic="true" name="applicationName" postBack="true" required="true" type="Application"/>
<Field displayName="Enter New Service Account Name" dynamic="true" name="ServiceAcctName" postBack="true" required="true" type="string">
<Attributes>
<Map>
<entry key="hidden">
<value>
<Script>
<Source>
import sailpoint.object.Field;
Field f8 = form.getField("accountType");
String f8value = f8.getValue();
boolean hideField = false;
if (!("Service Account is type of NPA that is used by an automated process and is not used in an interactive way by a user".equalsIgnoreCase(f8value))) {
hideField = true;
field.setRequired(false);
} else {
field.setRequired(true);
}
return hideField;
</Source>
</Script>
</value>
</entry>
</Map>
</Attributes>
<Script>
<Source>
import sailpoint.tools.Util;
String savedValue = Util.isNotNullOrEmpty(ServiceAcctName) ? ServiceAcctName : "SVC-";
return savedValue;
</Source>
</Script>
<ValidationScript>
<Source>
import java.util.regex.Pattern;
import java.util.regex.Matcher;
String regex = "(?i)Admin|Adm|Administrator|Root|Privileged|Priv|Super|Power|Pwr|PA|HPA|[@#\\$%&*_=+ ]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(value);
if (matcher.find()) {
return "Input String contains Non-Allowed Special Characters or SubStrings";
}
if (value.length() > 20) {
return "Length of Input should not be greater than 20";
}
if ("SVC-".equals(value)) {
return "Input cannot be just 'SVC-'. Please provide a more specific name.";
}
return null;
</Source>
</ValidationScript>
</Field>
Above is the code of two field in Sailpoint identity IQ environment form. In âServiceAcctNameâ field I have added few filters, and need to add one more filter which will check that the application selected in field âapplicationNameâ does not have any account with the same name as entered by user in âServiceAcctNameâ.
I tried adding code but its getting stuck in between and giving warning that Application is not selected but actually I have selected application.
Below is the code I have tried but did not work. Any suggestions to improve this.
<ValidationScript>
<Source>
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.Link;
import java.util.List;
// Validate restricted words and special characters
String regex = "(?i)Admin|Adm|Administrator|Root|Privileged|Priv|Super|Power|Pwr|PA|HPA|[@#\\$%&*_=+ ]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(value);
if (matcher.find()) {
return "Input String contains non-allowed special characters or substrings.";
}
if (value.length() > 20) {
return "Length of input should not be greater than 20 characters.";
}
if ("SVC-".equals(value)) {
return "Input cannot be just 'SVC-'. Please provide a more specific name.";
}
// Retrieve application name safely
Object appField = form.get("applicationName");
String selectedAppName = (appField != null) ? appField.toString().trim() : "";
if (selectedAppName.isEmpty()) {
return "Please select an application before entering a service account name.";
}
// Get SailPoint context
if (context == null) {
return "Error retrieving SailPoint context.";
}
// Check if the entered service account name already exists in the selected application
QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq("application.name", selectedAppName));
qo.addFilter(Filter.eq("nativeIdentity", value));
List links = context.getObjects(Link.class, qo);
if (links != null && !links.isEmpty()) {
return "The entered service account name already exists for the selected application. Please choose a different name.";
}
return null;
</Source>
</ValidationScript>