Determining if a User is a Member of a Team in SalesLogix Web

Five years ago I wrote a post about how to determine if a user is a member of a team in SalesLogix LAN scripts that is still referred to today. I’ve been asked on occasion how one would go about doing the same in the SalesLogix Web platform, so I thought it was time for a follow up post. In this post I will demonstrate how to use a HQL query to create a reusable function in the SalesLogix Web platform to determine whether a user is a member of a specified team.

We will be creating this as a reusable method that we’ll pass a User object to as well as the team name we want to check. Let’s look at the code first and then we’ll look at how to use it and where you might create this reusable code:

private bool IsUserOnTeam(Sage.Entity.Interfaces.IUser user, string team)
using (NHibernate.ISession session = new Sage.Platform.Orm.SessionScopeWrapper())
return 0 < Convert.ToInt32(session.CreateQuery("select count(*) from OwnerRights r where r.Owner.OwnerTypeChar = :type and r.Owner.OwnerDescription = :teamname and r.User.Id = :accessid")
.SetAnsiString("type", Sage.SalesLogix.Security.StringEnum.GetStringValue(Sage.SalesLogix.Security.OwnerType.Team))
.SetAnsiString("teamname", team)
.SetAnsiString("accessid", user.Id.ToString())

The code above queries the SalesLogix entity model, looking at the OwnerRight entity specifically (this maps to the SECRIGHTS table in the database), and then limits that with conditions that the OwnerTypeChar property has the corresponding value for a team, the OwnerDescription has the correct team name, and to limit that to the OwnerRight entity instance where the UserId matches the Id of the User we pass in.

The code to use it might look something like this:

Sage.SalesLogix.Security.SLXUserService usersvc = (Sage.SalesLogix.Security.SLXUserService)Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
Sage.Entity.Interfaces.IUser user = usersvc.GetUser();

if (IsUserOnTeam(user, "Midwest"))
// user is on the Midwest team
// user is NOT on the Midwest team

Now, where might we implement something like this? Personally, I would create this as a separate assembly in Visual Studio and plug in where needed. However, you could also implement this in a business rule as well. If you implemented this code in a business rule, you’ll need to make sure the rule has the correct references. Otherwise it will produce an error when you build the web platform saying something about “are you sure you are not missing an assembly reference?”.

By default, the rule will have references to the following:

  • Sage.Entity.Interfaces.dll
  • Sage.Form.Interfaces.dll
  • Sage.Platform.dll

For the code I outlined above, you’ll also need to have references for:

  •  NHibernate.dll
  • Sage.SalesLogix.Security.dll

I won’t go into a whole lot of details now about how to add these references, I’ll have those steps outlined in a future post. However, while in the rule editor, open the Property pane (F4), click the drop-down at the top of the Properties pane and select “Sage.Platform.Orm.Entities.CodeSnippetHeader”. Then you’ll see properties for the CodeSnippetHeader for your code. You can bring up the AssemblyReferences and add the ones I mention above to that dialog. Things should complile fine now and you could shorten the code a bit too since you can add usings for these namespaces and drop the fully-qualified names of the objects. Just make sure you don’t try to add this rule to the User or other Security entities (See Accessing User and Security Entity Properties in SalesLogix Web)

One that thing I wanted to point out as well. The Owner object in Sage.SalesLogix.Security also has a similar function that will return a List<Owner> of all teams a specified user belongs to. That can come in handy as well. Here’s a sample that you could add to a LoadAction on a form to display a list of the teams the current user belongs to in a multi-line TextBox on the form called QFTextBox (Note: for this code, you do need a Sage.SalesLogix.Security.User object, not just a Sage.Entity.Interfaces.IUser reference since the method specifically takes a User, not IUser, parameter):

Sage.SalesLogix.Security.SLXUserService usersvc = (Sage.SalesLogix.Security.SLXUserService)Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Security.IUserService>();
Sage.SalesLogix.Security.User user = usersvc.GetUser();

System.Collections.Generic.IList<Sage.SalesLogix.Security.Owner> teamlist = Sage.SalesLogix.Security.Owner.GetTeamsByUser(user);

string list = string.Empty;
foreach (Sage.SalesLogix.Security.Owner team in teamlist)
list += team.OwnerDescription + "rn";
QFTextBox.Text = list;

This code could also be used to check if a member is on a given team. However, the implementation of the method used in the Owner object will also return all the data in the List as well (and if I would have just used that I couldn’t have shown you the example using the HQL query).


Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Just what I was looking for, thanks Ryan!


Submit a Comment

Your email address will not be published.

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!