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"? ... 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):
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:
And this is the result:
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.
In this table, you can set up the roles that this specific user should be able to select.
//*** WALDO >>IF NOT MySessionMgt.CurrentProfileSelected THEN BEGINMySessionMgt.SetCurrentProfile(UserProfileMgt.SelectRoleCenter);EXIT(MySessionMgt.GetCurrentRoleCenterID);END;//EXIT(ConfPersMgt.DefaultRoleCenterID); //Removed..//*** WALDO <<
There are two newly created codeunits in this trigger:
SelectRoleCenter() : IntegerSIDConversion.SETCURRENTKEY(ID);SIDConversion.ID := USERID;IF SIDConversion.FIND THEN BEGINIF UserPersonalization.GET(SIDConversion.SID) THEN BEGINIF UserPersonalization."Profile ID" <> '' THEN BEGINIF Profile.GET(UserPersonalization."Profile ID") THEN BEGINIF Profile."Role Center ID" <> 0 THEN BEGINEXIT(Profile."Role Center ID");END;END;ENDELSE BEGINUserProfiles.SETCURRENTKEY("User SID");UserProfiles.SETRANGE("User SID", UserPersonalization."User SID");UserProfilesCount := UserProfiles.COUNT;IF UserProfilesCount = 1 THEN BEGINUserProfiles.FINDFIRST;Profile.GET(UserProfiles."Profile ID");Profile.TESTFIELD("Role Center ID");EXIT(Profile."Role Center ID");END;IF UserProfilesCount > 1 THEN BEGINIF PAGE.RUNMODAL(PAGE::"User Profiles",UserProfiles) = ACTION::LookupOK THEN BEGINProfile.GET(UserProfiles."Profile ID");Profile.TESTFIELD("Role Center ID");EXIT(Profile."Role Center ID");END;END;END;END;END;
//*** The DefaultEXIT(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" :-).
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 ?
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.
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?