Highlighted
Contributor
Contributor

current business group

Jump to solution

Hi,

Can you please help me to find query the business group that current (or specific user) is belong with VRO?

I was trying to do it on that way but getting null:

//vcacHost and userName are input parameter

var model = "ManagementModelEntities.svc";

var entitySetName = "Users";

var property = new Properties();

property.put("UserName",userName);

var entities = vCACEntityManager.readModelEntitiesByCustomFilter(vcacHost.id, model, entitySetName, property, null);

//System.log("User ent: " + entities);

var BG = entities[0].getLink(vcacHost, "ProvisioningGroup");

System.log("Bg New: " + BG);

Thanks,

Anat

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Expert
Expert

I've done this using the following approach

function stringArrayContains(arrStr, str)

{

     for each(var s in arrStr)

     {

          if(s == str)

          {

               return true;

          }   

     }

     return false;

}

var searchUser = "user@domain.com";

var allGrps = vCACCAFEEntitiesFinder.getBusinessGroups(vcacHost);

for each (grp in allGrps)

{

     // this will be an array of Strings

     var users = grp.getUsers();

     // Note to Vmware - a native array.contains method would be really handy here!

     if(stringArrayContains(grp.getUsers(), searchUser))

     {

          return grp;

     }

}

return null;

This will get you the first vCACCAFE:BusinessGroup the user is a member of (you might need to factor the group name if he's in multiple). This will also work if you want to check for an admin or support user. Have a look at the API documentation for the type vCACCAFE:BusinessGroup (open the API Explorer & keep it open Smiley Happy )

HTH

View solution in original post

0 Kudos
7 Replies
Highlighted
Expert
Expert

I've done this using the following approach

function stringArrayContains(arrStr, str)

{

     for each(var s in arrStr)

     {

          if(s == str)

          {

               return true;

          }   

     }

     return false;

}

var searchUser = "user@domain.com";

var allGrps = vCACCAFEEntitiesFinder.getBusinessGroups(vcacHost);

for each (grp in allGrps)

{

     // this will be an array of Strings

     var users = grp.getUsers();

     // Note to Vmware - a native array.contains method would be really handy here!

     if(stringArrayContains(grp.getUsers(), searchUser))

     {

          return grp;

     }

}

return null;

This will get you the first vCACCAFE:BusinessGroup the user is a member of (you might need to factor the group name if he's in multiple). This will also work if you want to check for an admin or support user. Have a look at the API documentation for the type vCACCAFE:BusinessGroup (open the API Explorer & keep it open Smiley Happy )

HTH

View solution in original post

0 Kudos
Highlighted
Contributor
Contributor

Hi,

Thank you eoinbyrneeoinbyrne, This work. Is any way to put the input (vcac host) on the script. I want to make an action without parameters.

thanks

0 Kudos
Highlighted
Expert
Expert

Take a look at Server.findAllForType in the API explorer

And / or read this post from qc4vmware - Server.findAllForType query parameter mystery solved (sorta)

0 Kudos
Highlighted
Contributor
Contributor

Hi,

I created dropdown successfully but the "var allGrps = vCACCAFEEntitiesFinder.getBusinessGroups(vcacHost); " take alot of time and user is waiting.

Is there other option to get the Business group if the user?

0 Kudos
Highlighted
Enthusiast
Enthusiast

You could try something like this:  parameters are vCACCAFEHost, tenantName, and username.

var authenClient = vCACCAFEHost.createAuthenticationClient();

var authenPrincipalSvc = authenClient.getAuthenticationPrincipalService();

var authenSubtenantSvc = authenClient.getAuthenticationSubtenantService();

// find the principal for the user

var principal = authenPrincipalSvc.getPrincipal(tenantName, username);

var vcacPrincipalId = principal.getPrincipalId();

// get the business groups

var businessGroups = authenSubtenantSvc.findSubtenantsByPrincipal(tenantName, vcacPrincipalId);

Hopefully the performance is better because you don't have to loop through all the users.

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi befreeman​,

I'm using your snippet and I got it for 98% working, the only thing is that for 2 different users I get 0 BG's returned.

I did check all objects and variables, they contain valid data and objects.

When I put "businessGroups" in a System.log(); then a empty string / array is returned. No error is being displayed.

Its this line:

var businessGroups = authenSubtenantSvc.findSubtenantsByPrincipal(tenantName, vcacPrincipalId);

Any thoughts?

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hi @Paul_SI,

Wow, this was a long time ago. Sorry, I don't even have a vRealize system running anymore. All I can think is maybe double check that the user is in a valid business group. If you're on a newer version of vRealize than this code might not be valid anymore. I want to say this was using vRA 7.0, not sure though.

Good luck!

0 Kudos