Parse error means there must be some syntax error. Could you please share the error message or provide some logs at which place it is throwing, etc., something like this?
Can you try by removing <String, Object> in the Map at line 18 ?
public String execute(Map context) {
And also use other object reference instead of context. if you are using it in the rule, then it might issue, because the rule itself is having context object reference by default.
thiis is my code without csv… maybe i am generating csv wrong way… actually i needed that csv to an email coz i couldnt specify path to export because we are doing it in cloud and we dont knw where is it saving
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 org.apache.log4j.Logger;
import java.util.*;
import sailpoint.object.*;
import sailpoint.object.Bundle;
import sailpoint.api.ManagedAttributer;
import sailpoint.tools.Util;
QueryOptions qo = new QueryOptions();
Iterator it = context.search(Bundle.class, qo);
String roleNames = "";
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) {
// Entitlement is missing in the catalog
roleNames += String.format("%s - Missing Entitlement: %s\n", bundle.getName(), entName);
}
}
}
}
}
}
}
}
}
TaskResult taskResult = context.getObjectByName(TaskResult.class, "AIZ-Missingentitlementreport");
if (taskResult != null) {
taskResult.setAttribute("roleNames", "Roles with missing entitlements:\n" + roleNames);
taskResult.setCompletionStatus(TaskResult.CompletionStatus.Success);
context.saveObject(taskResult);
}
// Return the list of role names
return roleNames;
so i am getting email with fille attached but one issue is its sending email to all sailpoint admins…shouldnt it be only sending to the address in the script?
<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 org.apache.log4j.Logger;
import java.util.*;
import sailpoint.object.*;
import sailpoint.object.Bundle;
import sailpoint.api.ManagedAttributer;
import sailpoint.tools.Util;
import sailpoint.object.EmailFileAttachment;
import sailpoint.object.EmailOptions;
import sailpoint.object.EmailTemplate;
import sailpoint.tools.EmailException;
QueryOptions qo = new QueryOptions();
Iterator it = context.search(Bundle.class, qo);
String roleNames = "";
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) {
// Entitlement is missing in the catalog
roleNames += String.format("%s - Missing Entitlement: %s\n", bundle.getName(), entName);
}
}
}
}
}
}
}
}
}
String toAddresses="[email protected]"; //change the To address
EmailOptions options = new EmailOptions(toAddresses, null);
byte[] postData = roleNames.getBytes();
EmailFileAttachment fileAttachment=new EmailFileAttachment("Test.csv", EmailFileAttachment.MimeType.MIME_CSV,postData);
options.addAttachment(fileAttachment);
// Construct an email template on the fly
EmailTemplate customTemplate = new EmailTemplate();
customTemplate.setName("Dynamic Missing Entitlements Report"); // Give a name
customTemplate.setSubject("Missing Entitlements Report"); // Set subject
customTemplate.setBody("Dear Recipient,\n\nPlease find attached the missing entitlements report for roles.\n\n" +
"Roles with missing entitlements:\n" + roleNames +
"\n\nBest regards,\nYour Team");
// Send email with the custom template
context.sendEmailNotification(customTemplate, options);
// Send email
context.sendEmailNotification(options);
TaskResult taskResult = context.getObjectByName(TaskResult.class, "AIZ-Missingentitlementreport");
if (taskResult != null) {
taskResult.setAttribute("roleNames", "Roles with missing entitlements:\n" + roleNames);
taskResult.setCompletionStatus(TaskResult.CompletionStatus.Success);
context.saveObject(taskResult);
}
return "Task completed successfully";
</Source>
</Rule>
Check the email settings in IdentityIQ configuration.
If the email notification type is set to redirection, it will send an email to the addresses specified in the redirection email address.