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

EXIT(ConfPersMgt.DefaultRoleCenterID);

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

EXIT(9006);

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
    MySessionMgt.SetCurrentProfile(UserProfileMgt.SelectRoleCenter);
    EXIT(MySessionMgt.GetCurrentRoleCenterID);
    END;
    //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.SETCURRENTKEY(ID);
    SIDConversion.ID := USERID;
    IF SIDConversion.FIND THEN BEGIN
    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");
    END;
    END;
    END
    ELSE BEGIN
    UserProfiles.SETCURRENTKEY("User SID");
    UserProfiles.SETRANGE("User SID", UserPersonalization."User SID");
    UserProfilesCount := UserProfiles.COUNT;
    IF UserProfilesCount = 1 THEN BEGIN
    UserProfiles.FINDFIRST;
    Profile.GET(UserProfiles."Profile ID");
    Profile.TESTFIELD("Role Center ID");
    EXIT(Profile."Role Center ID");
    END;
    IF UserProfilesCount > 1 THEN BEGIN
    IF PAGE.RUNMODAL(PAGE::"User Profiles",UserProfiles) = ACTION::LookupOK
    THEN BEGIN
    Profile.GET(UserProfiles."Profile ID");
    Profile.TESTFIELD("Role Center ID");
    EXIT(Profile."Role Center ID");
    END;
    END;
    END;
    END;
    END;
     

    //*** The Default
    EXIT(ConfPersMgt.DefaultRoleCenterID);

    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" :-).

Posted: 2010-7-13 23:08 by waldo | with 26 comment(s) |
Bookmark and Share

Comments

# re: Select Role when logging into NAV 2009 RTC

Great feature, Waldo. MS should adopt this. Having said that: whhy don't you log this as a suggestion on MSConnect. I certainly will vote in favour of it.

Thanx for sharing!

Wednesday, July 14, 2010 9:17 AM by Luc van Vugt

# re: Select Role when logging into NAV 2009 RTC

Thanks, Luc.

Well, it's a little bit "raping" the DefaultRoleCenter-trigger, so I don't think Microsoft will adopt this feature ;°).  

I'm using it in our db now, and I must say ... it's useful (allthough I say it myself) :-)

Wednesday, July 14, 2010 9:38 AM by waldo

# re: Select Role when logging into NAV 2009 RTC

Hmm. nice trick. I guess it's usable in a development environment.

Wednesday, July 14, 2010 10:51 AM by robbenguido

# Sharing & Synchronicity

Ever since, what in retrospect became, the final album of The Police , the concept of synchronicity has

Wednesday, July 14, 2010 5:54 PM by Van Vugt's dynamiXs

# Sharing & Synchronicity

Ever since, what in retrospect became, the final album of The Police , the concept of synchronicity has

Wednesday, July 14, 2010 6:09 PM by Van Vugt's dynamiXs

# re: Select Role when logging into NAV 2009 RTC

Waldo, thanks for mentioning that idea came from 1ClickFactory :)

Link to original article could be found here www.1clickfactory.com/index.php

Thursday, July 15, 2010 1:10 PM by Viktoras

# re: Select Role when logging into NAV 2009 RTC

It doesn't work on FR 2009 SP1 I have an error on RTC

Thursday, July 22, 2010 2:51 PM by Laurent

# re: Select Role when logging into NAV 2009 RTC

Can you share the error message?  

Monday, July 26, 2010 9:35 AM by waldo

# re: Select Role when logging into NAV 2009 RTC

Eric, you're a genius!

Tuesday, July 27, 2010 12:16 AM by Alex Chow

# re: Select Role when logging into NAV 2009 RTC

Is that the error message? ;°)

So you find it useful?

Tuesday, July 27, 2010 9:00 AM by waldo

# re: Select Role when logging into NAV 2009 RTC

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

Tuesday, July 27, 2010 6:45 PM by Alex Chow

# re: Select Role when logging into NAV 2009 RTC

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!

Tuesday, July 27, 2010 11:20 PM by waldo

# re: Select Role when logging into NAV 2009 RTC

Sorry Waldo I was on vacation

Error is :

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

Thursday, August 12, 2010 4:54 PM by Laurent

# re: Select Role when logging into NAV 2009 RTC

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

Thursday, August 12, 2010 5:12 PM by waldo

# re: Select Role when logging into NAV 2009 RTC

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

Thursday, August 12, 2010 6:07 PM by Laurent

# re: Select Role when logging into NAV 2009 RTC

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, ..)?

Monday, August 16, 2010 4:46 PM by waldo

# re: Select Role when logging into NAV 2009 RTC

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

Friday, August 20, 2010 12:05 PM by Felice

# re: Select Role when logging into NAV 2009 RTC

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

END;

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?

Friday, August 20, 2010 12:38 PM by waldo

# re: Select Role when logging into NAV 2009 RTC

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.

Friday, August 20, 2010 1:49 PM by Felice

# re: Select Role when logging into NAV 2009 RTC

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...

Friday, August 20, 2010 1:56 PM by waldo

# re: Select Role when logging into NAV 2009 RTC

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.

Wednesday, October 06, 2010 10:58 PM by Willy

# re: Select Role when logging into NAV 2009 RTC

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 ?

Friday, October 22, 2010 3:21 PM by Steve

# re: Select Role when logging into NAV 2009 RTC

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.. .

Friday, October 22, 2010 3:30 PM by waldo

# Select Role when logging into NAV 2009 RTC (v2)

May be you remember, but not too long ago, I wrote a small piece of functionality to select a role when

Thursday, December 02, 2010 5:09 PM by Waldo's Blog <br /> Microsoft Dynamics NAV

# Select Role when logging into NAV 2009 RTC (v2)

May be you remember, but not too long ago, I wrote a small piece of functionality to select a role when

Thursday, December 02, 2010 6:06 PM by Waldo's Blog Microsoft Dynamics NAV

# re: Select Role when logging into NAV 2009 RTC

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

Tuesday, July 05, 2011 5:03 PM by waldo

Leave a Comment

(required) 
(required) 
(optional)
(required)