
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 |
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; |
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; |
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; |
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; } |
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 FilesSalesLogixReferenceAssemblies).
Ryan
Excellent blog, this helped me loads.
Henry
are you getting the workspace using NavWorkspace instead of ToolbarWorkspace ?