Before operation rule for add entitlement

Hi ,
im receiving an error saying “soruce json is not a map”
what might be the issue?

import java.util.Map;
import connector.common.JsonUtil;
import connector.common.Util;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;

Map body = requestEndPoint.getBody();
String jsonBody = (String) body.get("jsonBody");
log.info("Rule - Modify Body: running");

try {
    // Parse JSON body into a map
    Map jsonMap = JsonUtil.toMap(jsonBody);
    String rolesProducts = "";

    // Extract roles-products from the provisioning plan
    if (provisioningPlan != null) {
        log.info("Rule - Modify Body: processing provisioning plan");
        for (AccountRequest accReq : Util.iterate(provisioningPlan.getAccountRequests())) {
            for (ProvisioningPlan.AttributeRequest attReq : Util.iterate(accReq.getAttributeRequests())) {
                String attrName = attReq.getName();
                if ("roles-products".equalsIgnoreCase(attrName)) {
                    rolesProducts = (String) attReq.getValue();
                    log.info("Rule - Modify Body: found roles-products = " + rolesProducts);
                    break;
                }
            }
        }
    }

    if (!rolesProducts.isEmpty()) {
        // Split roles-products into roleName and productName
        String roleName = "";
        String productName = "";
        String[] parts = rolesProducts.split(":");
        if (parts.length == 2) {
            roleName = parts[0].trim();
            productName = parts[1].trim();
        }

        // Add roleName and productName to the JSON map
        jsonMap.put("roleName", roleName);
        jsonMap.put("productName", productName);
        log.info("Rule - Modify Body: roleName = " + roleName + ", productName = " + productName);
    }

    // Serialize updated JSON map and update the request body
    String finalBody = JsonUtil.render(jsonMap);
    body.put("jsonBody", finalBody);
    requestEndPoint.setBody(body);
} catch (Exception ex) {
    log.error("Rule - Modify Body: " + ex);
}

Seems String jsonBody = (String) body.get(“jsonBody”); is not returning anything.

Can u try this? Not sure if this works

import java.util.Map;
import connector.common.JsonUtil;
import connector.common.Util;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;


String jsonBody = (String) requestEndPoint.getBody();
log.info("Rule - Modify Body: running");

Its not working , same error . I’m guessing the same. The first statement is not readin the data properly

input : account:preparer
i need to split this data
expected output
rolename: account
productname: preparer

This part is not correct,

I think you should rather have

    JsonObject jsonMap = new JsonParser().parse(jsonBody).getAsJsonObject();

and then treat it like json object instead of Map

You will need to import all or some of the following

    import com.google.gson.Gson;
    import com.google.gson.JsonArray;
    import com.google.gson.JsonElement;
    import com.google.gson.JsonPrimitive;
    import com.google.gson.JsonObject;
    import com.google.gson.JsonParser;
    import connector.common.JsonUtil;

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