show screen to certain group only

Hello

In service, we have two different usergroups who needs different kind of information from service module. I have created a screen for both of them, but i do not know, how to present one screen to one group and the other to second group. I know how to show screen to one person only (for testing purposes). Tried to change user -> group, but did not seemd to work.

if (getVariable("activeUser") == "222")
setVariable("url", getProgramTicket() + "&action=doScreenDefinition&idString=ej_viewTicket_80_aspa&entryId=" + getVariable("id"));

I appreciate, if somebody can help me with this, please.

regards

Ingar

RE: show screen to certain group only

Hi Ingar!

To get a list of the variables available through getVariable() you could do something like:

Map m = getVariables();
while(!m.eof()){
  print(m.getKey() + "|" + m.getVal() +"\n");
  m.next();
}

Which gives you (as an example):

AIMRevision|8.3.0000.0
AIMVersion|8.3.0000.0
activeAssociateId|8
activeUser|16
activeUsername|HW
debugId|
serverName|online.superoffice.com
userLang|en

As you can see, usergroup is not one of them.

 

What you can do is to use getVariable("activeUser") to find the usergroup:

User u;
u.load(getVariable("activeUser").toInteger());
print(u.getValue("group"));

So, just do a check on u.getValue("group").

Av: Hans Wilhelmsen 30. maj 2018

RE: show screen to certain group only

Thanks Hans

Works like a charm.

Av: Ingar Mölder 30. maj 2018

RE: show screen to certain group only

Hans' code is correct, but I would advice to use User u = getActiveUser(); instead as it uses the cached version of the User instead of loading the object all over.

You can do it like this:

// Loads the user and fetches the group
User u = getActiveUser();
String group = u.getValue("group");

// If group is the only thing you need, do this:
String group = getActiveUser().getValue("group");

You won't notice the difference with only one change like this, but I always try to optimalize the code for better load time.

Av: Simen Mostuen Iversen 30. maj 2018