Hi Team,
We have created a report and scheduled the report daily. Requirement is we need to remove headers from the report and send to the mail to the respective users
Can you please suggest on this
We have created a report and scheduled the report daily. Requirement is we need to remove headers from the report and send to the mail to the respective users
Can you please suggest on this
Hi Suresh Reddy
To remove headers from a scheduled report in SailPoint IdentityIQ and email it to respective users, you can follow below steps:
Customize the Report Output Format
Bean Shell Snippet to Remove Header from CSV
Sample Code:-
import java.io.;
import java.util.;
import sailpoint.tools.GeneralException;
// Path to the report file in the destination
String reportPath = “C:/Users/Gopal/Documents/reports/dailyReport.csv”;
// Read the file and skip the first line (header)
BufferedReader reader = new BufferedReader(new FileReader(reportPath));
List lines = new ArrayList();
String line;
boolean isFirstLine = true;
while ((line = reader.readLine()) != null) {
if (isFirstLine) {
isFirstLine = false; // Skip header
continue;
}
lines.add(line);
}
reader.close();
// Write back the file without header
BufferedWriter writer = new BufferedWriter(new FileWriter(reportPath));
for (String l : lines) {
writer.write(l);
writer.newLine();
}
writer.close();
import sailpoint.object.EmailOptions;
import sailpoint.object.EmailTemplate;
import java.util.HashMap;
import java.util.Map;
public void sendEmail(){
try{
//Variables which is needed in Email Template as per requirement
Map optionsMap = new HashMap();
optionsMap.put(“subject”, “User details Report”);
//Fetching Email Template
EmailTemplate emailTemplate = context.getObject(EmailTemplate.class, "Sample Email Template");
EmailOptions options = new EmailOptions();
options.setTo("test@abc.com");
options.setCc("test1@abc.com");
options.setVariables(optionsMap);
//Preparing Attachment
String fileName="userReport.csv";
byte[] parsedFileData = fileData.toString().getBytes("UTF-8");
EmailFileAttachment attachment = new EmailFileAttachment(fileName, EmailFileAttachment.MimeType.MIME_CSV, parsedFileData);
options.addAttachment(attachment);
//Sending Email
context.sendEmailNotification(emailTemplate, options);
catch (Exception e)
{
log.error("Exception while sending Email:: "+e)
}
}
}
sendEmail();