# How To Get Account Link Groups Using BeanShell Script

**URL:** <https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818>\
**Category:** IIQ Discussion and Questions\
**Created:** [June 23, 2021, 6:09am UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818 "2021-06-23T06:09:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakesh007](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakesh007/32/262_2.png) [@Rakesh007](https://developer.sailpoint.com/discuss/u/Rakesh007)\
**Post date:** [June 23, 2021, 6:09am UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/1 "2021-06-23T06:09:32Z")

</div>

Hello Developers,  
Hope Everyone well.  
I have a requirement in my local machine, how to get Account(Link) groups in the form.  
Because I’m building Modify Workflow for Windows Local application connector.  
For that, I need to get **remove** ManagedAttribute in the form dynamically.  
When I choose Identity in the first option then the second option gets dynamically.  
Can anyone help me with this and pls provide a snippet of code.

I’m attaching a screenshot for better clarification.

 ![image](https://global.discourse-cdn.com/sailpoint/original/1X/05e2d30be938d5d3183498031905d8b469e0b86e.png)  
Topic on IIQ Forum [Link](https://community.sailpoint.com/t5/IdentityIQ-Forum/How-To-Get-Account-Link-Groups-Using-BeanShell-Script/td-p/195663)  
Any help appreciated.  
Thanks,  
Rakesh Vadnala

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 23, 2021, 4:22pm UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/2 "2021-06-23T16:22:15Z")

</div>

Hey @Rakesh007 Thanks for posting in the developer forum.

I am asking around internally to see if anyone knows the answer to your question. Please hang tight while we look into this matter for you.

---

<div class="post-metadata">

**Author:** ![Rakesh007](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakesh007/32/262_2.png) [@Rakesh007](https://developer.sailpoint.com/discuss/u/Rakesh007)\
**Post date:** [June 23, 2021, 4:38pm UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/3 "2021-06-23T16:38:14Z")

</div>

@jordan.violet thanks for your reply.

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [June 24, 2021, 5:49pm UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/4 "2021-06-24T17:49:58Z")

</div>

@Rakesh007, Have you had a chance to look at the BeanShell Developer’s Guide for IdentityIQ? [https://community.sailpoint.com/docs/DOC-3375](https://community.sailpoint.com/docs/DOC-3375). There is some helpful information in that document.

---

<div class="post-metadata">

**Author:** ![anon87158948](https://avatars.discourse-cdn.com/v4/letter/a/e95f7d/32.png) [@anon87158948](https://developer.sailpoint.com/discuss/u/anon87158948)\
**Post date:** [June 24, 2021, 7:10pm UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/5 "2021-06-24T19:10:34Z")

</div>

Hi @Rakesh007, You may be able to achieve this by simply using the OOTB Access Request feature. Is there any specific reason you want to build custom form for it? Out of the Box Access Request feature will allow you to Add new access as well as revoke existing access.

 ![image](https://global.discourse-cdn.com/sailpoint/original/1X/93fd9a15622cd1eb6847d1cae0d35bd179e1738a.png)

Also, Have you looked at the PS offering of Group Management? Please see if you can utilize it.  
[https://community.sailpoint.com/t5/Professional-Services/AD-Group-Management/ta-p/136738](https://community.sailpoint.com/t5/Professional-Services/AD-Group-Management/ta-p/136738)

---

<div class="post-metadata">

**Author:** ![Rakesh007](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakesh007/32/262_2.png) [@Rakesh007](https://developer.sailpoint.com/discuss/u/Rakesh007)\
**Post date:** [June 27, 2021, 4:44am UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/6 "2021-06-27T04:44:57Z")

</div>

Hello @anon87158948,  
Thanks for your reply.  
In the form, I’m choosing identity as the first variable column.  
In the second column, Then I want to get identity entitlements or groups which are linked with that identity from the WindowsLocal application.  
I want to retrieve identity(account) groups dynamically in the form.

Can you please provide me how to achieve this with the BeanShell script?

Regards,  
Rakesh.

---

<div class="post-metadata">

**Author:** ![paul\_wheeler](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@paul\_wheeler](https://developer.sailpoint.com/discuss/u/paul_wheeler)\
**Post date:** [June 28, 2021, 9:03am UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/7 "2021-06-28T09:03:46Z")

</div>

Hi @Rakesh007

You could use a rule to get the list of values. For Windows Local the _groups_ attribute on the Link holds the list of group names that the account is a member of. In this code I’ve assumed your Windows application is called “Windows Local” and that there is only one Windows account per identity. You can modify the code if there can be more than one, but you would probably want a dropdown in the form to specify the account if that is the case.

```auto
  import sailpoint.api.IdentityService;
  import sailpoint.object.Application;
  import sailpoint.object.Identity;
  import sailpoint.object.Link;
 
  String appName = "Windows Local";

  List groups = new ArrayList();
  Application app = context.getObjectByName(Application.class, appName);
  IdentityService identityService = new IdentityService(context);
  List windowsLinks = identityService.getLinks(identity, app);

  if (null != windowsLinks && !windowsLinks.isEmpty()) {
    Link link = windowsLinks.get(0); // Assuming only one account
    groups = link.getAttribute("groups");
  }

  return groups;

```

---

<div class="post-metadata">

**Author:** ![Rakesh007](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakesh007/32/262_2.png) [@Rakesh007](https://developer.sailpoint.com/discuss/u/Rakesh007)\
**Post date:** [June 29, 2021, 10:57am UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/8 "2021-06-29T10:57:59Z")

</div>

HI @paul_wheeler ,  
I appreciate for your helping.  
I have a doubt in the snippet of code.  
So, here what is **identity** here.  
Should i replace identity with my form Identity variable??  
Regards,  
Rakesh

---

<div class="post-metadata">

**Author:** ![paul\_wheeler](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@paul\_wheeler](https://developer.sailpoint.com/discuss/u/paul_wheeler)\
**Post date:** [June 29, 2021, 12:14pm UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/9 "2021-06-29T12:14:50Z")

</div>

Hi @Rakesh007

The identity needs to be the identity you have selected in the first field. So you need to take the identity variable from your field and reference it in the code. Depending on how that comes back you may need to use context.getObjectByName or context.getObjectById to get the identity object from the name or id.

Paul

---

<div class="post-metadata">

**Author:** ![Rakesh007](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/rakesh007/32/262_2.png) [@Rakesh007](https://developer.sailpoint.com/discuss/u/Rakesh007)\
**Post date:** [June 29, 2021, 12:33pm UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/10 "2021-06-29T12:33:34Z")

</div>

Thank you so much @paul_wheeler

---

<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 19, 2023, 2:25pm UTC](https://developer.sailpoint.com/discuss/t/how-to-get-account-link-groups-using-beanshell-script/818/11 "2023-07-19T14:25:09Z")

</div>

Closed on July 19, 2023, 2:25pm UTC


