Trigger email notification when AccountRequest operation failied when using JDBC Rule

I tried to use JDBC Rule like below and add below codes, however it seems that context does not exist.

			    //This is the logic what i would like to add, however there is No context object based on my understanding.
			    EmailTemplate createTemplate = context.getObjectByName(EmailTemplate.class, "Access Request Cancelled");
				EmailOptions options = new EmailOptions();
				options.setTo("****@abc.com");

				Map args = new HashMap();
				args.put("content","This is for test");
				options.setVariables(args);
				context.sendEmailNotification(createTemplate,options);			
				//TO DO

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import java.util.ArrayList;

import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import sailpoint.object.ProvisioningResult;
import java.sql.Connection;
import java.sql.DriverManager;

import sailpoint.api.SailPointContext;
import sailpoint.connector.JDBCConnector;
import sailpoint.object.ProvisioningPlan.PermissionRequest;

public String getAttributeRequestValue(AccountRequest acctReq, String attribute) {

if (acctReq != null) {
    AttributeRequest attrReq = acctReq.getAttributeRequest(attribute);
    if (attrReq != null) {
        Object valObj = attrReq.getValue();
        log.error("AttriReq.getValue CLASS===========================" + valObj.getClass());
        String resultStr = valObj.toString();

        if (!(valObj instanceof String)) {
            int sLength = resultStr.length();
            resultStr = resultStr.substring(1, sLength - 1);
        }

        return resultStr;

    } else {
        return null;
    }

}

return null;

}

public String getAttrReqOpName(AccountRequest acctReq, String attribute) {

if (acctReq != null) {
    AttributeRequest attrReq = acctReq.getAttributeRequest(attribute);
    if (attrReq != null) {
        return attrReq.getOperation().name();
    }
}
return null;

}

log.error(“This is the DWH-CCS application rule”);
// DWH CSS/OPS/PI using same accessmenulist and detail in crm.APPACCESSDETAIL
// can NOT distinguish them only by detail
String ACCESS_MENU_LIST = “1”;
String APP_ID = “72”; // CCS APP ID
ProvisioningResult result = new ProvisioningResult();
PreparedStatement statement;
if (plan != null) {
log.error(“This is the first log for DWH-CCS-----------------------------------------------------------------------------”);
List accounts = plan.getAccountRequests();
if ((accounts != null) && (accounts.size() > 0)) {
for (AccountRequest account: accounts) {
try {
String nativeIdentity = account.getNativeIdentity();
String levelName = getAttributeRequestValue(account, “LEVELNAME”);
String firstName = getAttributeRequestValue(account, “FIRSTNAME”);
String lastName = getAttributeRequestValue(account, “LASTNAME”);

            log.error("this is operation: ----------------------------------------" + account.getOperation());
            log.error("This is NativeIdentity--------------:" + nativeIdentity);
            log.error("This is USERID--------------:" + getAttributeRequestValue(account, "USERID"));
            log.error("This is LEVELNAME--------------:" + levelName);
            log.error("This is FIRSTNAME--------------:" + firstName);
            log.error("This is LASTNAME--------------:" + lastName);
            log.error("This is APP_ID--------------:" + APP_ID);

            if (AccountRequest.Operation.Create.equals(account.getOperation())) {
			

            } else if (AccountRequest.Operation.Modify.equals(account.getOperation())) {
			
               //TO DO

            } else if (AccountRequest.Operation.Disable.equals(account.getOperation())) {

              //TO DO

            } else if (AccountRequest.Operation.Enable.equals(account.getOperation())) {

			//TO DO

            } else if (AccountRequest.Operation.Lock.equals(account.getOperation())) {

                // Lock, not supported.

            } else if (AccountRequest.Operation.Unlock.equals(account.getOperation())) {

                // Unlock, not supported.

            } else {
                // Unknown operation!
            }

        } catch (SQLException e) {
            result.setStatus(ProvisioningResult.STATUS_FAILED);
            result.addError(e);
        } finally {
            if (statement != null) {
                statement.close();
            }
        }
    }
}

}

return result;
}

Context is built in variable and should be accessible in the SailPoint rules, what happens if you attempt to print, does it return null or object?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.