How where to upload WebServiceBeforeOperationRule

I created a “WebServiceBeforeOperationRule” but I have no idea how this rule can be tested.

Could anyone advice me anything?

import java.util.*;
import connector.common.JsonUtil;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import sailpoint.connector.webservices.Endpoint;

// Get request endpoint
Endpoint requestEndPoint = (Endpoint) args.get("requestEndPoint");

// Extract attribute values from provisioning plan
ProvisioningPlan plan = (ProvisioningPlan) args.get("provisioningPlan");
String email = null;
String phone = null;

if (plan != null && plan.getAccountRequests() != null) {
    for (AccountRequest acctReq : plan.getAccountRequests()) {
        if ("Source ABC".equalsIgnoreCase(acctReq.getApplicationName())) {
            for (AttributeRequest attrReq : acctReq.getAttributeRequests()) {
                if ("secondaryEmail".equals(attrReq.getName())) {
                    email = (String) attrReq.getValue();
                }
                if ("phoneCallCell1".equals(attrReq.getName())) {
                    phone = (String) attrReq.getValue();
                }
            }
        }
    }
}


// Get existing attributes from Source ABC
Map<String, Object> existingAttributes = (Map<String, Object>) args.getOrDefault("existingAttributes", new HashMap<>());

String existingEmail = (String) existingAttributes.get("secondaryEmail");
String existingPhone = (String) existingAttributes.get("phoneCallCell1");


// Build dynamic payload
List<Map<String, Object>> payloadList = new ArrayList<>();

// Email logic
if (email != null) {
    Map<String, Object> emailPayload = new HashMap<>();
    if (existingEmail == null || "".equals(existingEmail)) {
        emailPayload.put("op", "add");
        emailPayload.put("path", "/paths/-");

        Map<String, Object> valueMap = new HashMap<>();
        valueMap.put("pathId", 240001148045317L); 
        valueMap.put("value", email);

        emailPayload.put("value", valueMap);
        
    } else if (!existingEmail.equals(email)) {
        emailPayload.put("op", "replace");
        emailPayload.put("path", "/paths/pathId:240001148045317/value");
        emailPayload.put("value", email);

        
    }
    if (!emailPayload.isEmpty()) {
        payloadList.add(emailPayload);
    }
}

// Phone logic
if (phone != null) {
    Map<String, Object> phonePayload = new HashMap<>();
    if (existingPhone == null || "".equals(existingPhone)) {
        phonePayload.put("op", "add");
        phonePayload.put("path", "/paths/-");

        Map<String, Object> valueMap = new HashMap<>();
        valueMap.put("pathId", 240001148045319L); 
        valueMap.put("value", phone);
        valueMap.put("countryCode", "US"); 

        phonePayload.put("value", valueMap);
        
    } else if (!existingPhone.equals(phone)) {
        phonePayload.put("op", "replace");
        phonePayload.put("path", "/paths/pathId:240001148045319/value");
        phonePayload.put("value", phone);

        
    }
    if (!phonePayload.isEmpty()) {
        payloadList.add(phonePayload);
    }
}

// Inject payload
if (!payloadList.isEmpty()) {
    String finalPayload = JsonUtil.render(payloadList);
    requestEndPoint.setPayload(finalPayload);
    
} else {
    
}

return requestEndPoint;

Thank you

See: Rule Development Kit | SailPoint Developer Community

In this document it references creation of testing rules. You would be able to validate the logic with test data and analyze the output.

Configure this rule in your source and depending upon for which operation you have configured this rule, perform that operation and you should be able to test your logic. Remember to add logging for troubleshooting for any error/failure.

Hi @j1241 Rita, you need to create this rule first using create-connector-rule | SailPoint Developer Community.

After that, attach this rule to your source using:

PATCH /v3/sources/{id}

Content-Type: application/json-patch+json

[  {    "op": "replace",    "path": "/connectorAttributes/connectionParameters/[*]/beforeRule",    "value": "Example Rule"  }]

Replace * with the index location of operation the way it is configured on the source. For example, 0, 1, 2, etc. You can use aGETcall on the source first to verify the index location prior to executing thePATCH call to attach the rule.

Once you attach the Rule to source, try testing the operation for which it is configured.

Hope this will help.

Thanks,
Saurav.

@j1241 : Use this for escape/unescape JSON for formatting the code:

You should be able to update the rule using the vscode ISC extension

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