Filter Lead-ListPage Detail

Hi,

I'm working on Lead Module. We have currently 20 leads records. Each Lead record is associated with a specific SBU such as: A, B, C. (below image)


Lead ListPage

 

Also, Users under the organizational roles are assigned roles that correspond to these SBUs i.e. A, B, C.

Query: When A User with Role 'A' log into Creatio, Only Leads with SBU 'A' should be displayed on Lead ListPage.

 

( I have used Handler method for this. User role is being fetched but lead-detail filter is not working.)
handlers: /**SCHEMA_HANDLERS*/[
         {
             request: "crt.HandleViewModelInitRequest",
             handler: async (request, next) => {
               await next?.handle(request);
               request.$context.events$.subscribe((async (evt) => {
           
      
                     const userId = Terrasoft.SysValue.CURRENT_USER.value;
                     console.log("userId >>", userId);
             
                     const esq = Ext.create("Terrasoft.EntitySchemaQuery", {
                         rootSchemaName: "SysUserInRole"
                     });
             
                     esq.addColumn("SysRole.Name", "RoleName");
                     esq.filters.addItem(
                         esq.createColumnFilterWithParameter(
                             Terrasoft.ComparisonType.EQUAL,
                             "SysUser",
                             userId
                         )
                     );
             
                     const roles = [];
             
                     // Wrap ESQ in Promise
                     await new Promise((resolve, reject) => {
                         esq.getEntityCollection((result) => {
                             if (!result.success) {
                                 reject(result);
                                 return;
                             }
                             result.collection.each(item => {
                                 roles.push(item.get("RoleName"));
                             });
                             resolve();
                         });
                     });
             
                     console.log("User Roles:", roles);
             
                     if (roles.length > 0) {
                       const filterGroup = Terrasoft.createFilterGroup();
                       filterGroup.logicalOperation = Terrasoft.LogicalOperatorType.OR;
                 
                       roles.forEach(role => {
                         console.log(role);
                         filterGroup.addItem(
                           Terrasoft.createColumnFilterWithParameter(
                             Terrasoft.ComparisonType.EQUAL,
                             "UsrSBU", // replace with your correct field
                             role
                           )
                         );
                       });
                 
                       // ✅ Reference to Lead datasource (PDS)
                       if (request.$context.PDS) {
                         request.$context.PDS.filters = filterGroup;
                         console.log("Filters applied to PDS datasource");
                       } else {
                         console.warn("PDS datasource not found in context!");
                       }
                     }
             
                 }));
                 
                 return next?.handle(request);
             }
         }
       ]/**SCHEMA_HANDLERS*/,

 

Platform: Creatio:Energy (Freedom UI)

Like 0

Like

2 comments

This might be easier with record access rights, plus it would be all no code. You could create three roles for SBU A, SBU B, and SBU C. Then, create a process that uses a signal of lead added (or also lead modified in the SBU column) that reads the Lead's SBU value and then removes the current access rights and assigns the appropriate/matching role to the leads. 

Then, add whatever uses to each of the roles. Then users on the role for SBU A would only see leads for SBU A. 

Ryan

Thanks for your response.

If I need to filter list-page records on some condition such as Name, SBU, Status, Lead Source or other fields, can't we do this using custom code or custom web-service?

Show all comments