Unable to fetch entitlement description for selected Application

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.

<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("Print the access: "+ selectedEntitlement); 
if (selectedEntitlement != null) { 
QueryOptions options = new QueryOptions(); 
options.addFilter(Filter.eq("value", selectedEntitlement)); 
String description = ""; 
Iterator it = context.search(ManagedAttribute.class, options, "attributes"); 
while(it != null &amp;&amp; it.hasNext()) { 
Object[] obj = it.next();
Attributes attrs = (Attributes) obj[0]; 
description = (attrs.get("sysDescriptions")).get("en_US");; 
log.error("Print the Description: "+ description);
          if(description !=null) { 
break; } } 
          
return description; 
} 
 
 </Source>
      </Script>
    </Field>

try adding the application filter to get entitlements for a particular app, something like this:

Filter sapAppFilter = Filter.like(“application.name”, “SAP”, MatchMode.START);

Filter requestableFilter = Filter.eq(“value”,selectedEntitlement);

Filter searchFilter = Filter.and(sapAppFilter,requestableFilter);

use this in your search

1 Like

@Chiru1307 -

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.

Cheers!!!

1 Like

I am trying to fetch entitlement Owner now in the same way but why I am getting Cannot access field: getOwner, on object:

      import sailpoint.object.QueryOptions; 
import sailpoint.object.Filter; 
import sailpoint.object. Application;
import sailpoint.object.ManagedAttribute; 
import sailpoint.object.Attributes; 
import sailpoint.tools.Util; 
log.error("Print the access: "+ selectedEntitlement);
log.error("Print the application: "+ selectedApp);
Application app = context.getObjectById(Application.class,selectedApp);
log.error("Print the app: "+ app);
if (selectedEntitlement != null) { 
          log.error("entered into if ");
QueryOptions options = new QueryOptions(); 
options.addFilter(Filter.and(
            Filter.eq("value", selectedEntitlement),
            Filter.eq("application", app)
        ));
Iterator it = context.search(ManagedAttribute.class, options); 
while(it != null &amp;&amp; it.hasNext()) { 
          log.error("Entered into while "); 
ManagedAttribute ma = (ManagedAttribute) it.next();
                     log.error("Entered into ma " + ma); 
                    return ma.getOwner();
} 
 }