Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

Creating Modules for SalesLogix Web and Hiding Toolbar Items at Runtime

Creating modules for SalesLogix Web is something that is likely something that is often overlooked or not used because they are assumed to be too complex or are just not understood. A module is an assembly that you've added to a page or the portal that adds functionality to the page. The great thing about a module is that you can change things about the page without needing to resort to doing something like modifying the deployed pages or SmartParts. This article will look at how to create a module to conditionally hide a menu item at runtime.

Note: In this article I will be creating a module that removes the "Import Leads" menu for users that are not on the Midwest team.

To create a module, you simply just need to create a new Class Library project in Visual Studio and reference some of the Sage DLLs. The main ones you'll likely need referenced are:

  • Sage.Platform.dll
  • Sage.Platform.Application.dll
  • Microsoft.Practices.ObjectBuilder.dll
There will be other DLLs that you'll likely need to reference as well depending on what exactly you're doing in the module. The sample module in this post does include many others. The main thing is that your class in the DLL will need to implement the IModule interface from Sage.Platform.Application.dll.

When you implement the IModule interface, there are two things you must implement. The void Load method and a ModuleWorkItem get property returning a WorkItem. The shell of your module will look something like this:

namespace FX.Modules
{
public class LeadMenuModule : Sage.Platform.Application.IModule
{
public void Load()
{
// implement load code here
}
public WorkItem ModuleWorkItem
{
get { return null; }
}
}
}

Now we'll need to add the code into our Load to do the work of checking to see the teams the user is on, and if not on the Midwest team to remove the menu item. However, in order to do that, we'll need to access some of the available services for things like getting the parent WorkItem, using the UserService to get the current user, and so forth. We can easily get the references through dependency injection by adding the following to our class:

using Sage.Platform.Application;
using Sage.Platform.Security;
//...

private UIWorkItem _parentWorkItem;
[ServiceDependency(Type=typeof(WorkItem))]
public UIWorkItem ParentWorkItem
{
get { return _parentWorkItem; }
set { _parentWorkItem = value; }
}

private IUserService _userService;
[ServiceDependency]
public IUserService UserService
{
set { _userService = value; }
get { return _userService; }
}

Having those dependencies will make the work easy from here on out. One of the things we'll need is to determine if the user is on a certain team or not as well. We can reference one of my earlier posts to determine that (See Determining if a User is a Member of a Team in SalesLogix Web).

Removing the Menu Item at Runtime

Before we look at the code altogether, let's take a look at how to remove the menu item at runtime. It is easy enough to do now that we'll have a reference to the page Work Item.

using Sage.Platform.WebPortal.Workspaces;
using Sage.Platform.WebPortal.Services;
using Sage.Platform.WebPortal.SmartParts;
//...

// Get the ToolbarWorkspace
ToolbarWorkspace toolbar = _parentWorkItem.Workspaces["ToolBar"] as ToolbarWorkspace;

// Get the MenuService for the ToolbarWorkspace
IMenuService menusvc = toolbar.WorkItem.Services.Get<IMenuService>();

// Find the "Tools" menu by it's ID
NavItemCollection navcol = menusvc.FindMenu("mnuTools") as NavItemCollection;
if (navcol != null)
{
// Remove the "Import Leads" menu by using it's ID
navcol.RemoveItem("tools_ImportLeads");
}

One thing to note is that if you look at a deployed page, such as the Account.aspx.cs file, you'll see that in the Page_Load, the menu's are constructed *before* the modules are loaded. So, when our module is added to the page, the menus will be loaded and ready for us.

Now, let's see the complete code for the module:

using System;
using System.Collections.Generic;
using Sage.Platform.Application;
using Sage.Platform.Application.UI;
using Sage.Platform.WebPortal.Services;
using Sage.Platform.WebPortal.Workspaces;
using Sage.Platform.WebPortal.SmartParts;
using Sage.Platform.Security;
using Sage.SalesLogix.Security;

namespace FX.Modules
{
public class LeadMenuModule : Sage.Platform.Application.IModule
{
public void Load()
{
User user = (_userService as SLXUserService).GetUser();
if (user.Id.ToLower().Trim()=="admin") return;
if (!IsOnTeam("Midwest", user))
{
ToolbarWorkspace toolbar = _parentWorkItem.Workspaces["ToolBar"] as ToolbarWorkspace;
IMenuService menusvc = toolbar.WorkItem.Services.Get<IMenuService>();
NavItemCollection navcol = menusvc.FindMenu("mnuTools") as NavItemCollection;
if (navcol != null)
{
navcol.RemoveItem("tools_ImportLeads");
}
}
}
public bool IsOnTeam(string teamname, User user)
{
bool res = false;
IList<Owner> teams = Owner.GetTeamsByUser(user);
foreach (Owner team in teams)
{
if (team.OwnerDescription.ToLower().Equals(teamname.ToLower()))
{
res = true;
break;
}
}
return res;
}
public WorkItem ModuleWorkItem
{
get { return null; }
}
private UIWorkItem _parentWorkItem;
[ServiceDependency(Type=typeof(WorkItem))]
public UIWorkItem ParentWorkItem
{
get { return _parentWorkItem; }
set { _parentWorkItem = value; }
}
private IUserService _userService;
[ServiceDependency]
public IUserService UserService
{
set { _userService = value; }
get { return _userService; }
}
}
}

Not too bad. It made fairly easy work to get the job done. Now we just add this assembly into the "bin" folder in the Support Files for the portal and then add the module in to the "Modules" tabs of the portal itself (not to a specific page) and the code will apply throughout the entire portal. On any page the user visits, the code will ensure the Import Leads menu item is removed.

Note, we could make this even more generic if we wanted to. Let's say we didn't want to hard-code the team name, or the menu item ID. We could simple add some properties to the class like this:

public TeamName { get; set; }
public MenuItemID { get; set; }

Now, when we add it to the portal we can click the "Configure" button next to it on the Modules tab and we'll see our properties for "TeamName and MenuItemID. We'd change the code to use those property values, instead of the hard coded ones, and then the administrator could simply use the Configure button to see the properties listed and enter the TeamName and MenuItemID to remove for anyone not on that team. Then a redeploy and the changes are live. Now you can change the values easily, without touching the code, or even reuse the module for something else.

If you want to take a look at the completed DLL (with the hard coded values), I've attached the Visual Studio project to this post (it will look for the references Sage DLLs in the usual Copy Assemblies location C:\Program Files\SalesLogix\ReferenceAssemblies).

  Attachment: LeadsMenuModule.zip

What's This?
  
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series



Related Content
   Easily Showing and Hiding Tabs at Runtime in Infor CRM (Saleslogix)
Showing and hiding tabs in the Infor CRM (Saleslogix) client should be an easy thing. It should be someth
Posted on Dec 16, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Problem setting SLXTextbox enabled property / Setting unexposed base control properties for a custom control
I recently had an issue with a Quickform where I was attempting to set the Enabled property of a TextBox
Posted on Dec 05, 2014 by Jason Buss to Jason Buss' Blog
 
   Checking Infor CRM (Saleslogix) Picklists for valid data
This week I received a question about a particular picklist. One of the picklist items, when chosen, wou
Posted on Dec 05, 2014 by Dale Richter to Infor CRM Questions & Answers
 
   Avoiding the Dirty Data Message When Programatically Redirecting to a Record in Infor CRM (Saleslogix)
In my last post I wrote about using the OnClientClick property of a control (or button) to run JavaScript
Posted on Dec 02, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Infor CRM (formerly Saleslogix) Web- Dependency Lookup OnChange Event Not Working Correctly
In the Saleslogix 8.1 web client the dependency lookup still has a problem with the OnChange event. 
Posted on Nov 26, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
Comments

 

Kris Halsrud said:

Great write up!

July 16, 2009 9:21 AM
 

Mark Dykun said:

Excellent Ryan, glad you covered the Module subject

July 17, 2009 11:05 AM
 

Henry Cohen said:

Ryan,

I'm trying to use similar code to hide a Nav Item and it is not working.

The problem is in this line of code:

NavItemCollection navcol = menusvc.FindMenu("navSales") as NavItemCollection;

It is not finding that menu. Any suggestions?

Thanks

~ Henry

October 2, 2009 1:22 PM
 

Tony Joanes said:

Ryan

Excellent blog, this helped me loads.

Henry

are you getting the workspace using NavWorkspace instead of ToolbarWorkspace ?

November 30, 2009 8:13 AM
 

Kris Halsrud's Blog said:

Ryan, wrote a great article on how to use a module to hide a toolbar item at runtime here. I wanted to expand his article slightly to show how a similar technique could be used to hide a context menu. The main difference is what workspace the context

April 20, 2010 3:21 PM
 

Kris Halsrud's Blog said:

Preventing errors from using Modules in the SalesLogix web client as it relates to the SalesLogix Web Reporting Server.

October 26, 2010 10:59 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register