Retrieving entitlements for the slected application in forms

Hi Team,
I want to create a form that retrieves the entitlements for the slected applicaion, but I am not able to retrive the entitlements.

<Field name="selectedEntitlement" displayName="Select Entitlement" type="string" required="true">
<AllowedValuesDefinition>
    <Script>
	<Source>
        <![CDATA[
            List values = new ArrayList();
            if (selectedApp != null) {
                Application app = context.getObjectByName(Application.class, selectedApp);
                if (app != null) {
                    List entitlements = app.getEntitlements();
                    for (Object ent : entitlements) {
                        if (ent != null) {
                            values.add(ent.toString()); 
                        }
                    }
                }
            }
            return values;
        ]]>
		</Source>
    </Script>
	</AllowedValuesDefinition>
</Field>

@Chiru1307 -

Try to below and let me know the outcome -

<!-- 1. Application picker (triggers refresh) -->
<Field name="selectedApp"
       displayName="Select Application"
       type="string"
       required="true"
       postBack="true">

  <AllowedValuesDefinition>
    <Script>
      <Source><![CDATA[
        import sailpoint.object.*;
        List apps = new ArrayList();
        for (Application a : context.getObjects(Application.class)) {
          apps.add(a.getName());          // value AND display label
        }
        return apps;
      ]]></Source>
    </Script>
  </AllowedValuesDefinition>
</Field>

<!-- 2. Entitlement picker, driven by the application above -->
<Field name="selectedEntitlement"
       displayName="Select Entitlement"
       type="string"
       required="true">

  <AllowedValuesDefinition>
    <Script>
      <Source><![CDATA[
        import sailpoint.object.*;
        import sailpoint.api.*;
        import java.util.*;

        List values = new ArrayList();

        // Read the choice made in the previous field
        String appName = (String) form.getValue("selectedApp");

        if (appName != null && appName.length() > 0) {
            Application app = context.getObjectByName(Application.class, appName);

            if (app != null) {
                // Query the entitlement catalog (ManagedAttribute objects)
                QueryOptions qo = new QueryOptions();
                qo.add(Filter.eq("application", app));
                Iterator it = context.search(ManagedAttribute.class, qo);     /* :contentReference[oaicite:2]{index=2} */

                while (it.hasNext()) {
                    ManagedAttribute ma = (ManagedAttribute) it.next();
                    // value() gives the raw entitlement; displayName() gives the friendly label
                    values.add(ma.getValue());          // or [ma.getValue(), ma.getDisplayName()]
                }
            }
        }
        return values;
      ]]></Source>
    </Script>
  </AllowedValuesDefinition>
</Field>

Cheers!!

I am getting error while running your code.

<Field displayName="Application" name="selectedApp" postBack="true" required="true" type="sailpoint.object.Application"/>
<Field displayName="Entitlements" filterString="application.name==&quot;Your_Applciation_name&quot;" name="entitlement" type="ManagedAttribute"/>

This filter code is working
but in Your_Applciation_name place I have to pass the selected app value automatically which I am not able to do.

Hi, what Sukanta is suggesting, that should work. You try adding void check along with null check.

<Field name="selectedEntitlement"
       displayName="Select Entitlement"
       type="string"
       required="true">

  <AllowedValuesDefinition>
    <Script>
      <Source><![CDATA[
        import sailpoint.object.*;
        import sailpoint.api.*;
        import java.util.*;

        List values = new ArrayList();

        // Read the choice made in the previous field
        String appName = (String) form.getValue("selectedApp");

        if (appName != void && appName != null && appName.length() > 0) {
            Application app = context.getObjectByName(Application.class, appName);

            if (app != null) {
                // Query the entitlement catalog (ManagedAttribute objects)
                QueryOptions qo = new QueryOptions();
                qo.add(Filter.eq("application", app));
                Iterator it = context.search(ManagedAttribute.class, qo);     /* :contentReference[oaicite:2]{index=2} */

                while (it.hasNext()) {
                    ManagedAttribute ma = (ManagedAttribute) it.next();
                    // value() gives the raw entitlement; displayName() gives the friendly label
                    values.add(ma.getValue());          // or [ma.getValue(), ma.getDisplayName()]
                }
            }
        }
        return values;
      ]]></Source>
    </Script>
  </AllowedValuesDefinition>
</Field>

@Chiru1307 - Mark it as solved

Cheers!!