Create new provisioning plan in before provisioning rule

Hello developers

I’m building a before provisioning rule for a web service connector which updates the final endpoint to place the role and the email user in the URL, however, the resulting URL concatenates the roles, that is, I require a structure like this for each entitlement:

https://mydomain.com/test/entitlementName1?action=add&[email protected]
https://mydomain.com/test/entitlementName2?action=add&[email protected]

But with this rule I get the URL with the concatenated entitlements separated by a comma:

https://mydomain.com/test/entitlementName1,entitlementName2?action=add&[email protected]

How can I make an event be processed for each entitlement to be added?

The rule I use is the following:

import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import java.util.List;
import java.util.Map;
import java.net.URLEncoder;

// Initialize variables
String userEmail = null;
String entitlementName = null;

// Retrieve user's email and entitlement name from the provisioning plan
if (provisioningPlan != null) {
    // Iterate over account requests
    List<AccountRequest> accountRequests = provisioningPlan.getAccountRequests();
    for (AccountRequest accountRequest : accountRequests) {
        // Get the native identity (user's account identifier)
        if (accountRequest.getNativeIdentity() != null) {
            userEmail = accountRequest.getNativeIdentity();
        }

        // Iterate over attribute requests to find email and entitlement name
        List<AttributeRequest> attrRequests = accountRequest.getAttributeRequests();
        if (attrRequests != null) {
            for (AttributeRequest attrReq : attrRequests) {
                String attrName = attrReq.getName();
                Object attrValue = attrReq.getValue();

                // Retrieve the user's email
                if ("email".equalsIgnoreCase(attrName) && attrValue != null) {
                    userEmail = attrValue.toString();
                }

                // Retrieve the entitlement name
                if ("entitlementName".equalsIgnoreCase(attrName) && attrValue != null) {
                    entitlementName = attrValue.toString();
                }
            }
        }
    }
}

// Handle missing email
if (userEmail == null || userEmail.isEmpty()) {
    throw new Exception("User email is not available in the provisioning plan.");
}

// Escape the '@' character in the email
String escapedEmail = userEmail.replace("@", "%40");

// Handle missing entitlement name
if (entitlementName == null || entitlementName.isEmpty()) {
    throw new Exception("Entitlement name is not available in the provisioning plan.");
}

// URL-encode the entitlement name
String encodedEntitlementName = URLEncoder.encode(entitlementName, "UTF-8");

// Construct the new endpoint URL
String baseUrl = "https://myserver.com/test/";
String newEndpointUrl = baseUrl + encodedEntitlementName + "?action=add&user=" + escapedEmail + "&parts=all";

// Set the new endpoint URL in the requestEndPoint
requestEndPoint.setFullUrl(newEndpointUrl);

// Optionally, log the new URL for debugging
log.info("Modified endpoint URL: " + newEndpointUrl);

// Return the modified requestEndPoint
return requestEndPoint;

I hope you can help me

Regards.