0 votes


From a workflow script I try to remove securities from specified users.

The documentation says that RemoveUsers only affect visible Users so it s not what I need.
I ve try to calculate the Users I want to keep in securities and apply a SetSecurityUsers because the documentation told me that the other users will be removed from security but this doesn't work either in Efficy SP2+
I ve try to used a custom storedProcedure to delete the Comp_User records, but this doesn't refresh my ContextHandle so basically it s not the good behaviour either.

Basically I just want to know how to remove a user from the securities of a record...

Please help.

asked in Efficy/ Client side by (986 points)
It seems that SetUserSecurity(EditHandle, K_USER, 0) AND the removeUsers do the job. Can you confirm that this is a clean way to do it?
Yes, use this

2 Answers

0 votes
Best answer

EDIT: without the rookie mistake:

This is the function I call from BeforeCommitComp (it seems to work fine)

function clearEntitySecurities(EditHandle, Entity, Key){

    var dsUsers = Database.getDetailDataSet(EditHandle, ntUser);
    dsUsers = dsToJson(dsUsers);
    dsUsers = dsUsers.map(function(_item){
        return _item.k_user;

    var dsAutoUsers = jsonSelectSQL("select K_USER from <#TABLE NAME=CUSTOM_AUTO_USERS>");
    dsAutoUsers = dsAutoUsers.map(function(_item){
        return _item.k_user;

    dsUsers = dsUsers.filter(function(_item){
        return (dsAutoUsers.indexOf(_item) >= 0); 

    Database.RemoveUsers(EditHandle, VarArrayOf(dsUsers));
    for (var i=0; i<dsUsers.length; i++){
        Database.SetUserSecurity(EditHandle, dsUsers[i], 0);

    return dsUsers;

please note that lot of polyfill are declared in custom scripts so don't try it withno "indexOf", "filter", "map", or "dsToJson" definition^^.

answered by (986 points)
selected by
You CANNOT use a database query on the data that is going to be changed in the BeforeCommit simply because the database is not yet updated.

You need to use the following dataset if you want access to your Comp_User table.

var dsCompUser = Database.getDetailDataSet(EditHandle, ntUser)

Btw, this is a classical mistake made by juniors
... at least I can feel like I am young again... I need some sleep. thanks Kristof.
0 votes

Hello Louis,

I am using the following fonction to do this, this my help you.
It may be possible to optimized it by not using the temporary array, but the import information here is that when you set the security to '0' Efficy will remove the user ;)

function clearSecurity(EditHandle) {
var userDs = Database.GetDetailDataSet(EditHandle, ntUser);
if (userDs && !userDs.IsEmpty) {
    var userArray = [];
    while (!userDs.Eof) {

    for (var i=0; i < userArray.length; i++) {
        var currentkUser = userArray[i];
        if (currentkUser > 0) {
            Database.SetUserSecurity(EditHandle, currentkUser, 0);


answered by (1.9k points)
1,226 questions
1,495 answers
328 users