0 votes

Efficy exposes a method forceUserRole to change the userrole during a session and also allows to change this from the Desktop bar.

What we seem to miss is a way to retrieve the current userrole. I don't find a tag, neither an API property or method.

Is it accessible by readSessionInteger?

The goal is to be able to switch form selection based on the currently selected user role

asked in WorkFlow / Serverscript by (7.4k points)
Hello Kristof. I am also in need to track the selected role in session to execute some workflow functionality.
May i ask how you got to store the selected role in session? So that i can use the ReadSessionInteger functionality?

Thank you.

Ken
What version are you going to use?
Client has version 11.1, so not able to use the CurrentUserRole function.

2 Answers

+1 vote

You're right, the method "CurrentUserRole" is currently not published in the scripting framework.
We'll add it in Efficy 11.2 - we can still squeeze it in right before the release.

If you need it in a previous version you'll have to make a query in ACC_ACCOUNTS.

answered by (1.2k points)
The query will not work, because when a role is changed in a session, it's not updated in the database. At our largest customer, we stored it in a custom sessions variable, so we never realized that the "getter" was missing.

Good that it will be added
Oh yes, the question has an overlap with the partitioning development in order to show custom forms, lookup content etc based on the users profile
The forced value can be found in the user settings:
ReadSessionInteger('SecurityContext', 'RoleID', 0)

Apparently this value is persistent, is that intended?
Are you sure it's not updated on logon with the value from ACC_ACCOUNTS.K_ROLE?
Great that we have a backwards solution with the ReadSessionInteger :-)
I don't see any code that resets the 'RoleID' integer variable at logon. It's only set in the ForceUserRole method, which is never called during logon.
Maybe I'm missing something...
What I expect from it is that it's not persistent and that the userrole is always defaulted with the database value. During the session, the userrole can be changed. Method CurrentUserRole should reflect always the current role of the session.
Please verify this.
If this has been developed for our largest customer, the development branch may not have been correctly merged in the trunk.
+1 vote

Hi Ken

For Efficy 11.1, the following Serverscript returns the currently selected role. Tested with Efficy 11.1.17608.0 and this request:

dialog?_macrofile=macroajax&_macro=runscript&file=securitycontext&func=currentUserRole

SecurityContext.js

/**
* Req: dialog?_macrofile=macroajax&_macro=runscript&file=securitycontext&func=CurrentUserRole
* Resp: {"k_Role":27,"userCode":"REGION_FR","userName":"France"}
*/
function CurrentUserRole() {
    var role = {
        k_Role: Efficy.ReadSessionInteger('SecurityContext', 'RoleID', 0),
        userCode: "",
        userName: ""
    }

    if (role.k_Role > 0) {
        role.userCode = Efficy.getUserCode(role.k_Role);
        role.userName = Efficy.getUserName(role.k_Role);
    }

    return JSON.stringify(role);
}
answered by (7.4k points)
1,247 questions
1,517 answers
1,858 comments
328 users