# How can i add entitlement inside IT role via rule

**URL:** <https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026>\
**Category:** IIQ Discussion and Questions\
**Tags:** rules, identityiq, entitlements, roles\
**Created:** [March 1, 2024, 6:15pm UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026 "2024-03-01T18:15:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanKsingh](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@amanKsingh](https://developer.sailpoint.com/discuss/u/amanKsingh)\
**Post date:** [March 1, 2024, 6:15pm UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026/1 "2024-03-01T18:15:12Z")

</div>

### Which IIQ version are you inquiring about?

Version 8.3

### Share all details related to your problem, including any error messages you may have received.

Hi All, I am able to add IT roles inside business role via rule role.addRequirement(ITROLENAME);. But I don’t know how can I add entitlement inside IT role?. Is there any API or something else by using able to add entitlement.

---

<div class="post-metadata">

**Author:** ![HemantSingh](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/hemantsingh/32/6737_2.png) [@HemantSingh](https://developer.sailpoint.com/discuss/u/HemantSingh)\
**Post date:** [March 1, 2024, 6:30pm UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026/2 "2024-03-01T18:30:39Z")

</div>

you can use assignProfiles method from bundle to add entitlements in role. Profile is needs to created based on application name and Constraints and within Constraints you need to set the Filter which is actually filter on entitlement … you can try something like below … its not full and working code but will an idea.

```auto
Profile profile = new Profile() ;
profile.setApplication(Application r);
profile.setConstraints(java.util.List<Filter> cons) 
assignProfiles(java.util.List<Profile> profiles)

```

---

<div class="post-metadata">

**Author:** ![amanKsingh](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@amanKsingh](https://developer.sailpoint.com/discuss/u/amanKsingh)\
**Post date:** [March 5, 2024, 8:27am UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026/3 "2024-03-05T08:27:09Z")

</div>

> [@HemantSingh](#):
>
> `java.util.List<Profile> profiles`

In assignprofiles if bundle don’t have any profile in list then how can i add new bundle and put that bundle inside assignProfiles as argument.

---

<div class="post-metadata">

**Author:** ![kavindar\_sharma](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/kavindar_sharma/32/4766_2.png) [@kavindar\_sharma](https://developer.sailpoint.com/discuss/u/kavindar_sharma)\
**Post date:** [March 5, 2024, 9:27am UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026/4 "2024-03-05T09:27:41Z")

</div>

Hi @amanKsingh

Please find the below code snippet to add profile into an itrole

```Profile
        profile.setApplication(appObj);
        profile.addConstraint(filter);
        itrole.add(profile);
        context.saveObject(itrole);
        context.commitTransaction();

```

---

<div class="post-metadata">

**Author:** ![Jarin\_James](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/jarin_james/32/3372_2.png) [@Jarin\_James](https://developer.sailpoint.com/discuss/u/Jarin_James)\
**Post date:** [March 5, 2024, 3:52pm UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026/6 "2024-03-05T15:52:19Z")

</div>

Hi @amanKsingh ,

Are you using the add method? I am just collating the above scripts.

```auto
import java.util.List;

import sailpoint.api.SailPointContext;
import sailpoint.object.Application;
import sailpoint.object.Bundle;
import sailpoint.object.Filter;
import sailpoint.object.Profile;

        Bundle itRole = context.getObjectByName(Bundle.class, <IT Role Name>);
        Filter filter = Filter.contains(<entitlement attribute>, <entitlement value>);
        Application application = context.getObjectByName(Application.class, <application name>);
        Profile newProfile = new Profile();
        newProfile.addConstraint(filter);
        newProfile.setApplication(application);
        itRole.add(newProfile);
        context.saveObject(itRole);
        context.commitTransaction();

```

---

<div class="post-metadata">

**Author:** ![amanKsingh](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@amanKsingh](https://developer.sailpoint.com/discuss/u/amanKsingh)\
**Post date:** [March 9, 2024, 9:39am UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026/7 "2024-03-09T09:39:32Z")

</div>

Hi @all,

I am using this code create new filter but i want to add inside filter value a list. Is there any method to add filter list inside filter.

```auto
for(Profile getprofile:ProfileList){
           System.out.println("600");
            getprofile.addConstraint(filter);
            System.out.println("700");
             //Profile.setApplication(application);
             System.out.println("800");
            // itRole.add(Profile);
            System.out.println("900");
             context.saveObject(itRole);
            System.out.println("1000");
             context.commitTransaction();

OUTPUT: <Profile created="170922974858847" id="0aaa25248e1e11f581218e2271ac5f3460">
      <ApplicationRef>
        <Reference class="sailpoint.object.Application" id="0aaa250d81af1d0d8181afbdc2e4c001d" name="My_Application"/>
      </ApplicationRef>
      <Constraints>
        <Filter operation="CONTAINS_ALL" property="groups">
          <Value>
            <List>
              <String>cn=*Test,ou=groups,ou=work,dc=test,dc=de</String>
            </List>
          </Value>
        </Filter>
        <Filter operation="CONTAINS_ALL" property="groups">
          <Value>
            <List>
              <String>cn=*Test,ou=groups,ou=work,dc=test,dc=de</String>
            </List>
          </Value>
        </Filter>
      </Constraints>
    </Profile>

**Need output like this:**

<Constraints>
        <Filter operation="CONTAINS_ALL" property="groups">
          <Value>
            <List>
              <String>cn=*Test,ou=groups,ou=work,dc=test,dc=de</String>
              <String>cn=*Test1,ou=groups,ou=work,dc=test,dc=de</String>
            </List>
          </Value>
        </Filter>
      </Constraints>

```

---

<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:** [May 8, 2024, 9:40am UTC](https://developer.sailpoint.com/discuss/t/how-can-i-add-entitlement-inside-it-role-via-rule/33026/8 "2024-05-08T09:40:13Z")

</div>

Closed on May 8, 2024, 9:40am UTC

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