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!!

So instead of adding in form can we change the logic in below custom plan

public ProvisioningPlan createPlan(Map inputData,String identityName,ProvisioningPlan plan)
	{
		ProvisioningPlan planModified=new ProvisioningPlan();
		
			//List inputData=new ArrayList();    -> passed as an argument to the method from caller workflow
			//String operation="";			-> passed as an argument to the method from caller workflow	

			List accountRequestList=new ArrayList();
			List provisioningTargetList=new ArrayList();
			String roleInfo = ""; [email protected]
			String comparePattern = "";
			String selectedBusinessRoleRemove = "";
			/* create a map with entitlement value and application */
			Map apptoValue=new HashMap();
			Map valuetoSchema=new HashMap();
			
			if(plan!=null){
			  List accounts = plan.getAccountRequests();
			  for (int i = 0; i &lt; accounts.size(); i++) {
				ProvisioningPlan.AccountRequest account = accounts.get(i);
				List attributes = account.getAttributeRequests();
				for (AttributeRequest attr: attributes) {
				  String appName=account.getApplication();
				  selectedBusinessRoleRemove = attr.getValue();
				  apptoValue.put(attr.getValue(),appName);
				  valuetoSchema.put(attr.getValue(),attr.getName());
				}
			  }
			}
			mylogger.info("IHG_Rule_Library:createPlan apptoValue----------"+apptoValue);
			mylogger.info("IHG_Rule_Library:createPlan valuetoSchema----------"+valuetoSchema);
			mylogger.info("IHG_Rule_Library:createPlan selectedBusinessRoleRemove----------"+selectedBusinessRoleRemove);	
		    boolean isInputDataAdded=false;
			for (Map.Entry entry : inputData.entrySet()) {
			AccountRequest accRequest=new AccountRequest();
			roleInfo = entry.getKey();
			//String eachData=roleInfo.split("\\|")[0];
			String[] pipeParts = roleInfo.split("\\|");
			String eachData = pipeParts.length > 0 ? pipeParts[0] : roleInfo;
			mylogger.info("IHG_Rule_Library:createPlan roleInfo#eachData----------"+roleInfo+"#"+eachData);
			/*if(eachData.contains("~"))
			{
				eachData=entry.getKey().split("~")[0];                                  //changed for manage access
			}*/
			if (eachData.contains("~")) {
				String[] tildeParts = eachData.split("~");
				eachData = tildeParts.length > 0 ? tildeParts[0] : eachData;
			}
			mylogger.info("IHG_Rule_Library:createPlan roleInfo#eachData----------"+roleInfo+"#"+eachData);

			String operation=entry.getValue();
		  
			QueryOptions Opts = new QueryOptions();
			Opts.addFilter(Filter.eq("displayName", eachData));
		
			Iterator results = context.search(ManagedAttribute.class, Opts);
			mylogger.info("IHG_Rule_Library:createPlan results----------"+results);
			String isRoleorEntitlement=null;
			String entitlementSchemaName="";

			String entitlementValue="";
			String objectId="";
			Application dataApplication=null;
			Bundle role=null;
		  
			if(results.hasNext())
			{ 
				isRoleorEntitlement="entitlement";
				ManagedAttribute  name =  results.next();
				objectId = name.getId();
				dataApplication=name.getApplication();
				entitlementSchemaName=name.getAttribute();
				entitlementValue=name.getValue();
			}
			else{
				role=context.getObjectByName(Bundle.class,eachData);
				if(role!=null){
				isRoleorEntitlement="role";
				objectId = role.getId();
				}	
			}
			Util.flushIterator(results);
			
			mylogger.info("IHG_Rule_Library:createPlan isRoleorEntitlement#objectId----------"+isRoleorEntitlement+"##"+objectId);

Can you please suggest on this?

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