Question

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 3

Like

5 comments

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

@kate is it possible in quantum

 

Hello,

Unfortunately, it still can’t be done using interface tools.

However, you can implement such a filter via code:

  1. Open your ListPage view model, add "@creatio-devkit/common" to SCHEMA_DEPS and sdk to SCHEMA_ARGS.
  2. 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"
					}
				]
 
			}
		}
	}
}

 

  1. 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:

Best regards,

Natalia

Natalia Kalynovska,

No Code?

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.

Show all comments