Getting Roles under Application

I have created two fields. One Field have Application name and other have roles.
I wanted to get the roles assigned to the selected application in above field. But could not figure out how to get the roles assigned to an application. Then I noticed that all the roles also contain the application name.

I want to display those roles which have atlease 3 starting characters matching with selected application. How Is this approach possible?

Below is the code I was using till now. How should I filter out roles?

<Section label="Application Name" name="Section 2">
    <Field displayName="Select" dynamic="true" name="Field_6" postBack="true" required="true" type="Application"/>
    <Field displayName="Roles" multi="true" name="Field_7" postBack="true" required="true" type="Bundle">
      <AllowedValuesDefinition>
        <Script>
          <Source>
            import sailpoint.tools.Util;
            import sailpoint.object.Bundle;
            import sailpoint.object.QueryOptions;
            import sailpoint.object.Filter;

            List roleList= new ArrayList();
            QueryOptions ops=new QueryOptions();
            ops.addFilter(Filter.eq("type","SAP"));
            Iterator it = context.search(Bundle.class, ops); 
            while ( (null != it) &amp;&amp; (it.hasNext()) ) { 
            Bundle record = (Bundle)it.next(); 
            roleList.add(record.getName()) ;
            }
            return roleList;
          </Source>
        </Script>
      </AllowedValuesDefinition>
    </Field>
  </Section>

Hi @pctripathi,

in you code you are filtering all bundles with “SAP” as type not as application.

Before all, when you work on object, follow the object model: Object Model

In this case, the application is not on the Bundle, but on the bundle profile:

Later, you can use the advanced analytics for build the filter:

with this you can build StringBuffer like this

StringBuffer sb = new StringBuffer();
sb.append("id.subquery(sailpoint.object.BundleProfileRelation, \"bundleId\", \"sourceApplication.name.startsWith(\"");
sb.append(appName);
sb.append("\"))");

qo = new QueryOptions();
qo.addFilter(Filter.compile(sb.toString()));

and for an exact match use sourceApplication.name ==