Hi Guys,
I am able to fetch entitlement description with this code but the issue comes when there are entitlement with same name but different application. I want to fetch the entitlement description for selected application entitlement.
You’re correctly fetching the ManagedAttribute by its value, but the problem arises because the value alone is not unique across applications — multiple applications can have entitlements with the same name. You need to filter by both value and the application name (or application ID) to uniquely identify the entitlement.
Here’s how you can fix your script by adding a filter for the application name (application.name) in addition to the value:
Updated Script (with application filter)
<Field displayName="Description" name="EntitlementDescription" postBack="true" readOnly="true" type="string">
<Script>
<Source>
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.ManagedAttribute;
import sailpoint.object.Attributes;
import sailpoint.tools.Util;
log.error("Selected Entitlement: " + selectedEntitlement);
log.error("Selected Application: " + selectedApp); // Ensure selectedApp is defined as a form field
if (selectedEntitlement != null && selectedApp != null) {
QueryOptions options = new QueryOptions();
options.addFilter(Filter.and(
Filter.eq("value", selectedEntitlement),
Filter.eq("application.name", selectedApp)
));
String description = "";
Iterator it = context.search(ManagedAttribute.class, options, "attributes");
while (it != null && it.hasNext()) {
Object[] obj = (Object[]) it.next();
Attributes attrs = (Attributes) obj[0];
if (attrs != null && attrs.get("sysDescriptions") != null) {
description = ((Map) attrs.get("sysDescriptions")).get("en_US");
log.error("Fetched Description: " + description);
if (description != null) break;
}
}
return description;
}
return "";
</Source>
</Script>
</Field>
Additional Notes:
Make sure selectedApp is another field in your form (with application name populated).
If you store application reference by ID or object name, adjust the Filter.eq("application.name", selectedApp) accordingly to use "application.id" or "application".
The "attributes" fetch strategy retrieves only the attributes object of the ManagedAttribute, improving performance.