ok here my code with file writer. but the error i get is
ERROR sailpoint.api.TaskManager:1007 - Exception: [sailpoint.tools.GeneralException: BeanShell script error: bsh.ParseException: Parse error at line 21, column 5. Encountered: ( BSF info: AIZ-TaskRule-RoleEntitlementMissing at line: 0 column: columnNo]
java.lang.Exception: sailpoint.tools.GeneralException: BeanShell script error: bsh.ParseException: Parse error at line 21, column 5. Encountered: ( BSF info: AIZ-TaskRule-RoleEntitlementMissing at line: 0 column: columnNo
QueryOptions qo = new QueryOptions();
Iterator it = context.search(Bundle.class, qo);
// CSV file name
String fileName ="exported_roles.csv";
try (FileWriter writer = new FileWriter(fileName)) {
// Write CSV header
writer.append("Role Name,Missing Entitlement\n");
while (it.hasNext()) {
Bundle bundle = it.next();
List profiles = bundle.getProfiles();
for (Profile profile : Util.safeIterable(profiles)) {
List constraints = profile.getConstraints();
for (Filter cons : Util.safeIterable(constraints)) {
Application app = profile.getApplication();
if (app != null) {
Schema accountSchema = app.getAccountSchema();
if (accountSchema != null) {
if (cons instanceof Filter.LeafFilter) {
String property = cons.getProperty();
Object value = ((Filter.LeafFilter) cons).getValue();
List valueList = new ArrayList();
// Check if the value is a List or String
if (value instanceof List) {
valueList.addAll((List) value);
} else if (value instanceof String) {
valueList.add((String) value);
}
for (String entName : valueList) {
if (property != null && entName != null) {
// Check if the entitlement exists in the ManagedAttribute catalog
ManagedAttribute ent = ManagedAttributer.get(context, app, property, entName);
if (ent == null) {
// Write the missing entitlement to the CSV
writer.append(bundle.getName()).append(",").append(entName).append("\n");
}
}
}
}
}
}
}
}
}
System.out.println("CSV file created successfully on your desktop!");
} catch (IOException e) {
e.printStackTrace();
}
return "CSV file created and saved to desktop!";
QueryOptions qo = new QueryOptions();
Iterator it = context.search(Bundle.class, qo);
// CSV file name
String fileName ="exported_roles.csv";
try {
FileWriter writer = new FileWriter(fileName);
// Write CSV header
writer.append("Role Name,Missing Entitlement\n");
while (it.hasNext()) {
Bundle bundle = it.next();
List profiles = bundle.getProfiles();
for (Profile profile : Util.safeIterable(profiles)) {
List constraints = profile.getConstraints();
for (Filter cons : Util.safeIterable(constraints)) {
Application app = profile.getApplication();
if (app != null) {
Schema accountSchema = app.getAccountSchema();
if (accountSchema != null) {
if (cons instanceof Filter.LeafFilter) {
String property = cons.getProperty();
Object value = ((Filter.LeafFilter) cons).getValue();
List valueList = new ArrayList();
// Check if the value is a List or String
if (value instanceof List) {
valueList.addAll((List) value);
} else if (value instanceof String) {
valueList.add((String) value);
}
for (String entName : valueList) {
if (property != null && entName != null) {
// Check if the entitlement exists in the ManagedAttribute catalog
ManagedAttribute ent = ManagedAttributer.get(context, app, property, entName);
if (ent == null) {
// Write the missing entitlement to the CSV
writer.append(bundle.getName()).append(",").append(entName).append("\n");
}
}
}
}
}
}
}
}
}
System.out.println("CSV file created successfully on your desktop!");
} catch (IOException e) {
e.printStackTrace();
}
return "CSV file created and saved to desktop!";
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="1726144527865" id="0a641a1f91b819bc8191e63b3df95554" language="beanshell" modified="1726249246250" name="AIZ-TaskRule-RoleEntitlementMissing">
<Description>Rule to check for roles that contain an entitlement which does not exist in the entitlement catalog</Description>
<Signature returnType="Map">
<Inputs>
<Argument name="log">
<Description>The log object associated with the SailPointContext.</Description>
</Argument>
<Argument name="context">
<Description>A sailpoint.api.SailPointContext object that can be used to query the database if necessary.</Description>
</Argument>
<Argument name="taskResult">
<Description>A sailpoint.object.TaskResult object that can be used to report task results to IIQ.</Description>
</Argument>
</Inputs>
<Returns>
<Argument name="roleNames">
<Description>Role names that are missing entitlements</Description>
</Argument>
</Returns>
</Signature>
<Source>
import sailpoint.object.TaskResult;
import sailpoint.object.QueryOptions;
import sailpoint.object.Identity;
import sailpoint.tools.Message;
import java.util.List;
import java.util.Map;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import org.apache.log4j.Logger;
import sailpoint.object.*;
import java.util.*;
import sailpoint.object.Bundle;
import sailpoint.api.ManagedAttributer;
QueryOptions qo = new QueryOptions();
Iterator it = context.search(Bundle.class, qo);
// CSV file name
String fileName ="exported_roles.csv";
try {
FileWriter writer = new FileWriter(fileName);
// Write CSV header
writer.append("Role Name,Missing Entitlement\n");
while (it.hasNext()) {
Bundle bundle = it.next();
List profiles = bundle.getProfiles();
if (profiles != null) { // Safe null check for profiles
for (Object objProfile : profiles) {
Profile profile = (Profile) objProfile;
List constraints = profile.getConstraints();
if (constraints != null) { // Safe null check for constraints
for (Object objCons : constraints) {
Filter cons = (Filter) objCons;
Application app = profile.getApplication();
if (app != null) {
Schema accountSchema = app.getAccountSchema();
if (accountSchema != null && cons instanceof Filter.LeafFilter) {
String property = cons.getProperty();
Object value = ((Filter.LeafFilter) cons).getValue();
List valueList = new ArrayList();
// Check if the value is a List or String
if (value instanceof List) {
valueList.addAll((List) value);
} else if (value instanceof String) {
valueList.add((String) value);
}
for (String entName : valueList) {
if (property != null && entName != null) {
// Check if the entitlement exists in the ManagedAttribute catalog
ManagedAttribute ent = ManagedAttributer.get(context, app, property, entName);
if (ent == null) {
// Write the missing entitlement to the CSV
writer.append(bundle.getName()).append(",").append(entName).append("\n");
}
}
}
}
}
}
}
}
}
System.out.println("CSV file created successfully on your desktop!");
} catch (IOException e) {
e.printStackTrace();
}
return "CSV file created and saved to desktop!";
</Source>
</Rule>
depeds on your installation. Sailpoint home is the folder where you can find identityiq folder.
Also, in your rule you are declaring this:
String fileName ="exported_roles.csv";
and you use it into the costructor of FileWriter without specifying the path. Without the path the rule will create the file in own folder(this is java not sailpoint) and I dont know where.
try to put the entire path and close the FileWriter.
It doesn’t work like that. I image you have installed SP in Azure, AWS or other. There you a VM with linux or windows. When you exucute the rule, you are exucuting on that machine, if put C:\folderblabla, the will save the on that cloud machine not in yours.
For save locally, you must connect the cloud to your pc. You can do that sharing folder betweet your pc and cloud machine, but that is little complex theme doesnt depends of SP.