Hello. I need to create a QuickFilter on a Freedom UI Page whose value will change dynamically. I found a post https://customerfx.com/article/using-custom-attributes-on-a-creatio-fre… so I try to use the attribute but it does not work. Could you help me please?
{ "filterType": 1, "comparisonType": 3, "isEnabled": true, "trimDateTimeParameterToDate": false, "leftExpression": { "expressionType": 0, "columnPath": "MyColumn" }, "isAggregative": false, "dataValueType": 1, "rightExpression": { "expressionType": 2, "parameter": { "dataValueType": 1, "value": "$MyAttribute" } } }
Like
Hello,
It seems that the attributes will not work properly with the filter, as an alternative I can suggest applying the full filter in a handler where you can change it as you want, for example:
handlers: /**SCHEMA_HANDLERS*/[ { request: "crt.HandleViewModelAttributeChangeRequest", handler: async (request, next) => { const result = await next?.handle(request); request.$context.DataGrid_7cyakqc_PredefinedFilter={"items": { "1893734f-7c93-40a5-9592-8e7231005e10": { "filterType": 1, "comparisonType": 7, "isEnabled": true, "trimDateTimeParameterToDate": false, "leftExpression": { "expressionType": 0, "columnPath": "Age" }, "isAggregative": false, "dataValueType": 4, "rightExpression": { "expressionType": 2, "parameter": { "dataValueType": 4, "value": 20 } } } }, "logicalOperation": 0, "isEnabled": true, "filterType": 6, "rootSchemaName": "Contact"}; return result; } } ]
Dmytro Vovchenko,
Hi, Where do I store the attributes for this predefined element? Do I have to create an attribute and bind it to the element?
Hi,
Attributes on a Freedom UI page should be declared in the page schema (viewModelConfigDiff -> attributes). If you want the filter value to be dynamic, you create an attribute and (optionally) bind it to an input, but the filter JSON itself will not automatically resolve $Attribute. Instead, just like in Dmytro’s example, you apply the filter programmatically in a handler and use the attribute’s value there.
For example, declare the attribute:
viewModelConfigDiff: [
{
"operation": "merge",
"path": ["attributes"],
"values": {
"MyFilterValue": { "value": "" }
}
}
]
And then in the handler:
handler: async (request, next) => {
const result = await next?.handle(request);
const term = await request.$context.MyFilterValue;
request.$context.DataGrid_7cyakqc_PredefinedFilter = {
"items": {
"1893734f-7c93-40a5-9592-8e7231005e10": {
// same structure as in Dmytro’s code,
// but instead of a constant value we use the attribute
"rightExpression": {
"expressionType": 2,
"parameter": {
"dataValueType": 4,
"value": term
}
}
}
},
"logicalOperation": 0,
"isEnabled": true,
"filterType": 6,
"rootSchemaName": "Contact"
};
return result;
}