Our company has a limited number of AX user licenses, as most companies will. Some people like to open multiple sessions (and eat up licenses) while they're working. We have asked people to stop this and we close their sessions when we notice that they have multiples open, but we wanted some way for the system to prevent this from happening.
I read about this idea on another blog, but I didn't save the link. It's the same general idea as they proposed, but I did it a little differently, in the end.
I created a table called UserSessionLimits. It has a field called UserID (extended data type is userId) and this is a mandatory field. It has another field called MaxSessions (this is an integer) and it also is mandatory. The index is UserIDx, it contains userid and it is unique.
The code that accesses this table is written so that if a user is not in this table, then they are limited to one session, so add users to this table if they are exceptions and you want them to be able to have more than one session open.
Add code to the "Info" class, in the startup() method. The Info class can only be accessed by going to the System Documentation area of the AOT.
In the startup method, at the top, I placed this code:
select count(recid) from sysClientSessions
where sysClientSessions.userId == curuserid() &&
sysClientSessions.Status == 1 &&
sysClientSessions.clientType == 0;
if(sysClientSessions.RecId > UserSessionLimits::getMaxSessions(curUserid()))
{
box::stop(strfmt("You have exceeded your session limit of %1, the application will now close",
UserSessionLimits::GetMaxSessions(curUserid())));
appl.globalcache().set(classstr(info),identifierStr(AutoLogoff), true);
this.shutDown(true);
}
By searching only for clientType = 0, you will only be looking for "User" sessions. Web sessions or worker sessions (batches that are running) will not be affected.
There have been times that people have gotten around this. They quickly opened two sessions immediately one after the other. If they are simultaneously opened, it's hard to catch. Also, sometimes this locks people out. If they were doing something and AX shut down on them or their system froze, sometimes it takes some time for the session to end for them to get back in again. Your network administrator can control when inactive sessions time out.
We also set automatic shutdown (in user options) to 60 minutes. So if their session is inactive for 60 minutes, it will close.
Update:
So we implemented this and found that sometimes people would see this box and never click OK. It is the user interaction that causes the session to close. So if they just leave the session up with the box open, then they can still open up a bunch of sessions and eat up our licenses. So we changed the code to show a progress box for 5 seconds instead of a box that requires user interaction. I made this a utility in case we ever needed a progress box that would show a message for a period time and then close automatically, we could call this code again. Here is the code:
static void timedProgressBox(int timetoWait, str caption, str text)
{
#AviFiles
AppTimer timer = new AppTimer();
SysOperationProgress progress = new SysOperationProgress();
int i ;
;
timer.Start();
progress.setAnimation(#AviStopWatch);
progress.setText(text);
progress.setCaption(caption);
progress.setTotal(timetoWait);
for (i = 0; timer.time() < timetoWait; i++)
{
timer.ticks();
progress.setCount(i,1);
i = real2int(timer.time());
}
progress.kill();
timer.Stop();
}
Hi Amber Rains
ReplyDeletei want UserSessionLimits table and GetMaxSessions method code
our company use ver AX4.0
please send to email my address reather@me.com
thank you for your help~
Sorry, I don't have an XPO file. The post above should be enough to get it working. Let me know if you have specific questions.
DeleteThanks!