Retrieving the Manager in SalesLogix 7.5 Web

The SalesLogix 7.5 web entity model, unfortunately, does not have access to a user’s manager by default.  Trying to expand the SalesLogix entity model is often problematic as the changes to the entity layer do not correctly compile into the security Assembly. 

User security is compiled in the Sage.SalesLogix.Security assembly.  This comprises the various entity objects for user, owner, owner rights, etc.  One of the entities defined in the security assembly is the “User” entity.  This entity represents the USERSECURITY table in SalesLogix which is where the MANAGERID field stores the corresponding USERID that represents the manager of the user.

If we examine the entity in the SalesLogix Application Architect we can see that the ManagerId property is not included within the entity model.

 SalesLogix User Entity

Ideally, you could simply add a new relationship within the User entity to join back to the USERINFO table which would then allow you to fetch the details of the manager, as shown here:

SalesLogix User Relationship

If you do create this relationship and build the SalesLogix Interfaces, you then see you can correctly access the managers information through the intellisense within the Application Architect.  For instance if you wanted to get the email address of an Opportunity Account Manager’s manager you could add this code:

SalesLogix User Code Snippet

However, when you actually build and deploy your site with this relationship established you will most likely receive an error such as “

Method ‘get_Manager’ in type ‘Sage.SalesLogix.Security.User’ from assembly ‘Sage.SalesLogix.Security, Version=7.5.0.1484, Culture=neutral, PublicKeyToken=null’ does not have an implementation.”

With Details such as:

Exception Details: System.TypeLoadException: Method ‘get_Manager’ in type ‘Sage.SalesLogix.Security.User’ from assembly ‘Sage.SalesLogix.Security, Version=7.5.0.1484, Culture=neutral, PublicKeyToken=null’ does not have an implementation.

SalesLogix Security Error

This would have to be considered a bug as the Application Architect allows you to add such a relationship and once added, the relationship seems to be functional until you deploy.  This is likely due to the fact that the compilation of the security assemblies in SalesLogix is not flexible enough to handle any changes to the core structure.  That being said what can you do?

Well fortunately there is a way to fetch the manager data like we were trying to do with a standard entity relationship.  The downside is it has to be done in code.  lets take a look at how it can be done:

In this example lets take a look at how to get the manager for the currently logged in user.  To get the current user we can use the SLXUserService implemented in the Sage.SalesLogix.Security namespace.  This code would look something like:

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();

This code returns “user” as object representing the User (USERSECURITY) interface for the currently logged in user.  Now with that we can get the current user ID with something like:

user.Id.ToString();

Now since there is no relationship from our User object to the manager’s USERINFO details we need to fetch this directly from the database.  To do this we can use the IDataService implementation in the Sage.Platform.Application assembly .  Using this allows us to get the current connection details and thus utilize standard ADO commands to fetch data from the database.  Lets look at what this code would look like:

Sage.Platform.Data.IDataService datasvc = Sage.Platform.Application.ApplicationContext.Current.Services.Get();

This code returns a “datasvc” object which can then be used to retrieve a connection string to use in our ADO commands:

datasvc.GetConnectionString();

With this we can now use the system OLEDB namespace to make calls directly to the database.  The following code runs a query to get the current user’s manager’s email.  It then sets the result into a string variable:

using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(datasvc.GetConnectionString()))
{
conn.Open();
using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("select u1.email from userinfo u1 inner join usersecurity u2 on u1.userid = u2.managerid where u2.userid = '" + user.Id.ToString() + "'", conn))
{
object o = cmd.ExecuteScalar();
if (o != null) mgremail = o.ToString();
}
}

So lets take a look at the complete code:

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();

string mgremail = string.Empty;
try
{
Sage.Platform.Data.IDataService datasvc = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Data.IDataService>();
using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(datasvc.GetConnectionString()))
{
conn.Open();
using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("select u1.email from userinfo u1 inner join usersecurity u2 on u1.userid = u2.managerid where u2.userid = '" + user.Id.ToString() + "'", conn))
{
object o = cmd.ExecuteScalar();
if (o != null) mgremail = o.ToString();
}
}
}
catch {}

A little bit of code to do what should be enabled with a simple entity relationship.  Hopefully in the near future this SalesLogix web interface security limitation will be removed, but for now maybe this article will help.

ABOUT THE AUTHOR

Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

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!