HOW TO FILTER LIST PAGE ACCORDING TO CURRENT USER CONTACT TYPE IN FREEDOM UI
HOW TO FILTER LIST PAGE ACCORDING TO CURRENT USER CONTACT TYPE IN FREEDOM UI
imagine that i have employer in marketing department and another employer in hr department
and i need to get records according to employer contact
if we type it in sql will be like this select * from courses where department = CURRENT_USER_CONTACT_DEPARTMENT
Like
Hello!
We have checked your request and unfortunately it is not possible to set up this filtration at the moment, but I registered this idea for our developers so that they would consider the possibility of implementing such functionality in future releases.
Thank you for this suggestion, this helps to make our product better!
Best regards,
Kate
Hello,
Unfortunately, it still can’t be done using interface tools.
However, you can implement such a filter via code:
- Open your ListPage view model, add "@creatio-devkit/common" to SCHEMA_DEPS and sdk to SCHEMA_ARGS.
- Complete the viewModelConfigDiff with a merge operation for attributes – add an empty attribute to store the filter and apply it to Items in “filterAttributes”:
{ "operation": "merge", "path": [ "attributes" ], "values": { "departmentFilter": {}, "Items": { "modelConfig": { "filterAttributes": [ { "loadOnChange": true, "name": "departmentFilter" } ] } } } }
- Add the crt.HandleViewModelInitRequest handler according to this example:
{ request: "crt.HandleViewModelInitRequest", handler: async (request, next) => { //Get the system value of the current user const sysValuesService = new sdk.SysValuesService(); const sysValues = await sysValuesService.loadSysValues(); const currentUser = sysValues.userContact; //Get the value of the current user’s department const contactModel = await sdk.Model.create("Contact"); const contact = await contactModel.load({ attributes: ["Id", "Department"], parameters: [{ type: sdk.ModelParameterType.PrimaryColumnValue, value: currentUser }] }); if(contact) { const department = contact[0]?.Department?.value; //Set the filter value if(department) { const filters = new sdk.FilterGroup(); filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, 'Department', department); request.$context.departmentFilter = filters; } } return next?.handle(request); } }
Here are some auxiliary materials:
- the system variables in Freedom UI - https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/category/system-variable, https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/platform-customization/freedom-ui/display-the-value-of-a-system-variable/references/system-variables-freedom-ui (the list);
- the instructions on working with the Model class - https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/front-end-development/freedom-ui/data-sources/crud_operations/references/model-class-js;
- setting up filtering in Freedom UI - https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/front-end-development/freedom-ui/data-sources/data-processing#title-2438-3.
Best regards,
Natalia
Julio.Falcon_Nodos,
Hello,
Currently, the filter based on a system value couldn’t be applied with no code tools. Our developers are considering the possibility of implementing this idea.