# Role retrival forms

**URL:** <https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100>\
**Category:** IIQ Discussion and Questions\
**Tags:** forms, workflows, provisioning, roles, identityiq\
**Created:** [May 8, 2025, 7:33am UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100 "2025-05-08T07:33:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chiru1307](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@Chiru1307](https://developer.sailpoint.com/discuss/u/Chiru1307)\
**Post date:** [May 8, 2025, 7:33am UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100/1 "2025-05-08T07:33:34Z")

</div>

I want create a form that gets the roles and role description from the selected application

```auto
<Field displayName="Select Role" name="selectedRole" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Script>
          <Source>
        import sailpoint.object.*;
        import sailpoint.api.*;
        import java.util.*;

        List values = new ArrayList();
            if(selectedApp != null){
          log.error("Print the application : "+ selectedApp); 
        // Read the choice made in the previous field
        Application app = context.getObjectById(Application.class,selectedApp);
             log.error("Print the app : "+ app);
            if (app != null) {
                QueryOptions qo = new QueryOptions();
                qo.add(Filter.eq("application", app));
                Iterator it = context.search(Bundle.class, qo);   
                  Bundle bu=(Bundle) it.next();
                while (it.hasNext()) {
                    it.next();
                    values.add(bu.getValue());
                }
            }
        return values;
            }
      </Source>
        </Script>
      </AllowedValuesDefinition>
    </Field>

```

---

<div class="post-metadata">

**Author:** ![enistriminsait](https://avatars.discourse-cdn.com/v4/letter/e/58f4c7/32.png) [@enistriminsait](https://developer.sailpoint.com/discuss/u/enistriminsait)\
**Post date:** [May 8, 2025, 8:48am UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100/2 "2025-05-08T08:48:03Z")

</div>

ok, and where is the problem?

---

<div class="post-metadata">

**Author:** ![Chiru1307](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@Chiru1307](https://developer.sailpoint.com/discuss/u/Chiru1307)\
**Post date:** [May 8, 2025, 8:55am UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100/3 "2025-05-08T08:55:23Z")

</div>

Hi @enistriminsait , As from your previous posts on role retrival forms I have observed that role application doesn’t saved on Bundle but on BundleProfilerelation. can you please help me on how can I do that

---

<div class="post-metadata">

**Author:** ![kalyan\_dev32](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/kalyan_dev32/32/21870_2.png) [@kalyan\_dev32](https://developer.sailpoint.com/discuss/u/kalyan_dev32)\
**Post date:** [May 8, 2025, 11:44pm UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100/4 "2025-05-08T23:44:16Z")

</div>

```auto
<Field displayName="Roles" dynamic="true" multi="true" name="rolesBasedOnApp" type="Bundle">
  <Script>
    <Source> 

    import sailpoint.object.QueryOptions;
    import sailpoint.tools.GeneralException;
    import sailpoint.tools.Util;

    String applicationId = "7f00000190431db2819075ff3b0d2a8e"; // get this dynamically
    List roleIds = new ArrayList();
    if(Util.isNotNullOrEmpty(applicationId)) {
      Map params = new HashMap();
      params.put("applicationId", applicationId);
      params.put("roleType", "it");

      QueryOptions qo = new QueryOptions();

      String query = "sql:select sb.id from identityiq.spt_bundle sb INNER JOIN identityiq.spt_bundle_profile_relation sbpr on sb.id = sbpr.bundle_id \n" +
        "WHERE sb.`type`=:roleType and sbpr.source_application=:applicationId";

      Iterator it = context.search(query, params, qo);
      while (it.hasNext()) {
        String roleId = (String) it.next();
        roleIds.add(roleId);
      }

      if (it != null) {
        Util.flushIterator(it);
      }
    }

    return roleIds;

    </Source>
  </Script>
</Field>

```

---

<div class="post-metadata">

**Author:** ![Chiru1307](https://avatars.discourse-cdn.com/v4/letter/c/bc79bd/32.png) [@Chiru1307](https://developer.sailpoint.com/discuss/u/Chiru1307)\
**Post date:** [May 9, 2025, 6:38am UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100/5 "2025-05-09T06:38:07Z")

</div>

Hi @kalyan_dev32 ,It is not entering into while. The query not returning any values.

---

<div class="post-metadata">

**Author:** ![kalyan\_dev32](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/kalyan_dev32/32/21870_2.png) [@kalyan\_dev32](https://developer.sailpoint.com/discuss/u/kalyan_dev32)\
**Post date:** [May 9, 2025, 8:07am UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100/6 "2025-05-09T08:07:00Z")

</div>

@Chiru1307 Add `applicationId` and `type` to the query and run it directly on the database to check for any results. then tweak the code accordingly.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [July 8, 2025, 8:07am UTC](https://developer.sailpoint.com/discuss/t/role-retrival-forms/126100/7 "2025-07-08T08:07:53Z")

</div>

Closed on July 8, 2025, 8:07am UTC

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