Select Role when logging into NAV 2009 RTC

Doing support on NAV 2009 RTC is a challenge. First of all, you've got the challenge of the customization-part (everyone can customize their pages to their own needs) .. and second, you've got the challenge of supporting the different roles: when someone from the warehouse has got a problem, you want to investigate that problem "in his role".

The second issue, I would like to address today in this blogpost.

In a way, we need to be able to select a role in a flexible way. First attempt .. I blogged about the use of CodeGenius .. actually, a way to use the shortcuts. And remember, this way (the shortcut-way) is the only way that is supported by Microsoft. You can read all about this way here. (how many times did I use the word "way"? Smile ... anyway ...).

Another solution could be: a possibility (avoiding every opportunity to use the word "way" now...) to select a rolecenter when you log into NAV 2009 RTC. Something like this (sorry for the Dutch roles...):

It should even be possible to add a role (profile) when it's not there in the list .. while logging in.
I got actually the idea from a newsletter from 1ClickFactory. I just built further on that.

So, what's the trick?

Actually, the only trick is in Codeunit 1, trigger "DefaultRoleCenter", which is not very straight-forward to understand... . The trigger is triggered when there is NO default RoleCenter. How can you set up a default Role Center? (Everyone should know this):

  • You can select the "Default Role Center" checkbox in the "Profile Card" page
  • You can set up a role center for a specific user in the "User Personalisation" page

So, if you did NOT do any of this .. the "DefaultRoleCenter"-trigger is "fired".

Furthermore, the trigger has got a return-value, being an integer. What could this be. Let's just look at the default code behind the trigger:

DefaultRoleCenter() : Integer


It calls function "DefaultRoleCenterID" in codeunit 9170 "Conf./Personalization Mgt.". When you look at that trigger, you'll see a very dumb function:

DefaultRoleCenterID() : Integer


Just a hardcoded return of the RoleCenter page 9006 (Order Processor). What's the advantage? Quite easy to understand .. and we can use this. We can create our own functionality to select that role center, can't we? In fact, let's create a functionality where YOU can select the rolecenter you want to log in.. . Even more, I want to be able to set up a different set of role centers per user. Even more .. I want to be able to set this up during log in.. .

Let's build it..

I will just provide you the objects, and explain the main points here. I tried not to build just the functionality, but I also tried to look at a somewhat bigger perspective ... I want to be able to use this tool in any database I'm going to deploy at any customer. These are the things we're going to do:

  • Provide an overall setup to (de-)activate this "feature"
    • When activated, the user shouldn't be able to select the "Default Role Center" checkbox, because that would de-activate the "DefaultRoleCenter"-trigger
    • When creating a new company, fill this setup table along with the others (default behaviour)
  • Provide a possibility to set up the role centers (profiles) a specific user wants to select
  • When logging in, provide the list of role centers (profiles) that was set up for that user and make that list editable, so that the user can add a profile if necessary.

And this is the result:

  1. A new setup window that can be reached from the departements, to activate and deactivate the functionality:

    With the small side-remark that I added some extra code in Codeunit 2 (Company-Initialize) to fill this new Setup-table.

    When this checkbox is ticked, it shouldn't be possible anymore to be able to set a default profile, therefore, I changed the OnValidate-trigger on table 2000000072 (Profile). I can understand you're not in favor doing this, but (as for as I know) it's the only way make sure the "DefaultRoleCenter"-trigger will always work.

  2. An extension in the User Personalisation (List & Card) to set up the profiles that a user wants to select. I created a new table and List-page to be able to do the setup.

    In this table, you can set up the roles that this specific user should be able to select.

  3. Change trigger "DefaultRoleCenter" in codeunit 1 to be able to select a rolecenter when logging in:

    DefaultRoleCenter() : Integer

    //*** WALDO >>
    IF NOT MySessionMgt.CurrentProfileSelected THEN BEGIN
    //EXIT(ConfPersMgt.DefaultRoleCenterID); //Removed..
    //*** WALDO <<

    There are two newly created codeunits in this trigger:

  • MySessionMgt is a singleinstance codeunit which I use to do session-related stuff. In this case, I want to be able to get (and set) the current profile from anywhere in my application, so I store it in the singleinstance. I also need it to be able to only select a role center once, because for some reason or another, the trigger "DefaultRoleCenter" is fired three times ... Tongue Tied.
  • UserProfileMgt is where the business logic is for selecting a profile, which became quite extensive ... but probably can be simplified a lot... I didn't put too much time into this:

    SelectRoleCenter() : Integer
    SIDConversion.ID := USERID;
    IF UserPersonalization.GET(SIDConversion.SID) THEN BEGIN
    IF UserPersonalization."Profile ID" <> '' THEN BEGIN
    IF Profile.GET(UserPersonalization."Profile ID") THEN BEGIN
    IF Profile."Role Center ID" <> 0 THEN BEGIN
    EXIT(Profile."Role Center ID");
    UserProfiles.SETCURRENTKEY("User SID");
    UserProfiles.SETRANGE("User SID", UserPersonalization."User SID");
    UserProfilesCount := UserProfiles.COUNT;
    IF UserProfilesCount = 1 THEN BEGIN
    Profile.GET(UserProfiles."Profile ID");
    Profile.TESTFIELD("Role Center ID");
    EXIT(Profile."Role Center ID");
    IF UserProfilesCount > 1 THEN BEGIN
    IF PAGE.RUNMODAL(PAGE::"User Profiles",UserProfiles) = ACTION::LookupOK
    Profile.GET(UserProfiles."Profile ID");
    Profile.TESTFIELD("Role Center ID");
    EXIT(Profile."Role Center ID");

    //*** The Default

    As you can see, there is a small trick to convert the USERID to the SID, which is used in the UserPersonalization. You can use table "SID - Account ID" for that... .

    If a certain ProfileID is set to the user, it will get that Profile and log in, without a pop up. If not, it's going the setup tables, and is going to show you the profile-selection-window (if more then one profile is selected). It's as easy as that... .

That's actually it. It's ridiculous to write such a long blogpost for such a small functionality. I just hope it's useful for you, and that you learned something new :-).

I made the objects available as a download on Mibuso. They're free and "as is" :-).

Comment List
  • By the way .. als you might have noticed .. there is a second version which holds the fix for the above issue :-)

  • Hi Steve .. I am aware of the problem, but I've not been able to search for a solution just yet .. .  Sorry for that.. .

    I will do so asap.. .

  • Hi Waldo, I like this alot.  But what I've just recently noticed is if a 'Profile ID' is not set on the use, you can not use 'Add Action on Role Center', as it errors saying

    the object metadata does not exist.  identification fields and values: object type='page',object id='0'

    if you set the 'Profile ID' or set a default on the user the 'Add Action on Role Center' works.

    Is there perhaps somewhere else that needs to call your MySessionMgt.GetCurrentRoleCenterID ?

  • Hi!

    I showed it to some of our sales people and the loved it :)

    only one little problem --> you are not able to save any filters  (save view as) as long as you use this tool. Then you will get an error in metadata (pageid = 0). Turning it of and use a default profile, will fix the problem with metadata when saving a filter.

  • Ah ok,

    So you have to add a number of profiles for your user in the "User Personalization" page with the "Multiple profile Selection" button...

  • I thought this flag is to switch the selction on/off in general when starting the RTC. I just implemented it myself to do so.

  • uhm, actually it is implemented like I intended .. .  And it HAS effect.  See the OnValidate trigger on table-level.

    IF "User Profile Selection Active" THEN BEGIN

     Profile.MODIFYALL("Default Role Center", FALSE, FALSE);


    The code is inteded to make sure that the "default" rolecenter is not selected (else, the trigger is not "triggered")

    I downloaded my own fob, and implemented it .. and all seems to be correct, no?

  • You forgot to implement the setup field "User Profile Selection Active" in your .fob Objects. It has no effect.

  • hm, try do delete the record from the Object Metadata table.. and recompile again?

    Sorry, I wouldn't know what the issue is in your case .. .

    Are you sure all build numbers are the same (classic, RTC, Server, ..)?

  • not change with recompile, and it seems to miss some dll

  • Seems you have to recompile (or may be edit and save) page 9003 .. make sure there is a new metadata-record...

  • Sorry Waldo I was on vacation

    Error is :

    metadata object record doest not exist. Indentification field and value : object type='page', object ID='9003'

  • Sure it's easier to use .. they changed less then I did ;°)

    It wasn't useful for our customers though .. They want a different setting for different users.. and not a complete list of rolecenters to choose from.  

    Anyway, thanks for the feedback!

  • I find it useful. But I find the code from 1ClickFactory a lot easier to use.

  • Is that the error message? ;°)

    So you find it useful?