The CreatorCon Call for Content is officially open! Get started here.

Restrict specific users to see records on list view

Souvick6917
Tera Contributor

Hi team,

Please help in achieving below requirement.

As a member of specific groups say group A and B, I will be able to view certain number of records on customer contact table. The table has field which is filtering the records I want to see.

I will only see the records which are fulfilling the condition and other records will not be available to me.

 

Thanks in Advance

Souvick

8 REPLIES 8

Toy will need 2 table level ACLs one for each group and in the condition you can add the condition for records they can see.

And 2 more acls , everything remaining same but tablename.*

-Anurag

Amit Pandey
Kilo Sage

Hi @Souvick6917 

 

You can use Query Business Rule to restrict records in list view. For the script, I will need complete requirement along with the fields names.

 

Regards,

Amit

Requirement as below:

Table:customer_contact

Field used to filter : Account.Functional scope = INTEGRA(This is the functional scope taken from the customer_account table and available under show related fields). Total 58 records out of 5500

Only Members of 4 groups (A,B,C,D) will be able to see the 58 records and the other records will not be available. 

 

Hi @Souvick6917 

 

Please use this and make adjustments accordingly. I had a similar requirement and it had worked-

 

 

(function executeRule(current, previous /*null when async*/) {

    // Define the condition for filtering records based on Functional Scope
    var functionalScopeCondition = "account.functional_scope = 'INTEGRA'";

    // Define the list of groups that can view the records
    var allowedGroups = ['A', 'B', 'C', 'D'];
    var userGroups = gs.getUser().getMyGroups();
    
    // Check if the current user is a member of any of the allowed groups
    var canViewRecords = false;
    for (var i = 0; i < userGroups.size(); i++) {
        var group = userGroups.get(i);
        if (allowedGroups.indexOf(group) !== -1) {
            canViewRecords = true;
            break;
        }
    }

    // If user is not a member of allowed groups, restrict access to all records
    if (!canViewRecords) {
        gs.info("User does not have access to view records.");
        current.addEncodedQuery("sys_id=NULL");
    }

    // Add the condition for Functional Scope to the query
    gs.info("Original query: " + current.getEncodedQuery());
    current.addEncodedQuery(functionalScopeCondition);
    gs.info("Modified query: " + current.getEncodedQuery());

})(current, previous);

 

 

This Business Rule checks if the user belongs to groups (A, B, C, D); if not, restricts access to records using sys_id=NULL, otherwise, applies a filter based on Account.Functional scope="INTEGRA"

 

Regards,

Amit