How to get current record id and Schema UId within a list filter in Freedom UI
Hello community!
I'm creating a list in the Case object's form page to display processes logs that are connected to the current record, so that I get a detailed trace of executions for any case record. I have already created the list to display the information and it is something like this:
As you may see, for this example the list retrieves only 1 record because there was only 1 execution of the process "Modify case" that was connected to the current case. If I run another process connected to this case I will have something like this:
My problem is that the filter implemented for the list has the Schema UId and record id hardcoded, as I don't know how to retrieve than information dynamically inside the filter configuration. With those hardcoded values, the information is fetched and filtered correctly, but I can't seem to implement it in a generic way. I've tried to get the current record id with things like:
- $Id
- $PDS.Id
- PDS.Id
- ProcessLogListDS.Id
But none of them seem to work. This is the page code with the filter configuration:
define("Cases_FormPage", /**SCHEMA_DEPS*/[]/**SCHEMA_DEPS*/, function/**SCHEMA_ARGS*/()/**SCHEMA_ARGS*/ {
return {
viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
...
]/**SCHEMA_VIEW_CONFIG_DIFF*/,
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
{
"operation": "merge",
"path": [
"attributes"
],
"values": {
"ProcessLogList": {
"isCollection": true,
"modelConfig": {
"path": "ProcessLogListDS",
"filterAttributes": [
{
"loadOnChange": true,
"name": "ProcessLogList_PredefinedFilter"
}
]
},
"viewModelConfig": {
"attributes": {
"ProcessLogListDS_Name": {
"modelConfig": {
"path": "ProcessLogListDS.Name"
}
},
"ProcessLogListDS_Id": {
"modelConfig": {
"path": "ProcessLogListDS.Id"
}
}
}
}
},
"ProcessLogList_PredefinedFilter": {
"value": {
"items": {
"masterRecordFilterWrapper": {
"filterType": 6,
"isEnabled": true,
"logicalOperation": 0,
"items": {
"masterRecordFilter": {
"filterType": 6,
"isEnabled": true,
"logicalOperation": 1,
"items": {
"entityFilter": {
"filterType": 5,
"comparisonType": 15,
"isEnabled": true,
"leftExpression": {
"expressionType": 0,
"columnPath": "[VwSysProcessEntity:SysProcess].Id"
},
"subFilters": {
"filterType": 6,
"isEnabled": true,
"logicalOperation": 0,
"items": {
"EntityIdFilter": {
"filterType": 1,
"comparisonType": 3,
"isEnabled": true,
"leftExpression": {
"expressionType": 0,
"columnPath": "EntityId"
},
"rightExpression": {
"expressionType": 2,
"parameter": {
"dataValueType": 1,
"value": "47b777ca-4d1e-46f2-b2dc-22324202db2e" // This is the current Case record id for the example
}
}
},
"SchemaUidFilter": {
"filterType": 1,
"comparisonType": 3,
"isEnabled": true,
"leftExpression": {
"expressionType": 0,
"columnPath": "SysSchema.UId"
},
"rightExpression": {
"expressionType": 2,
"parameter": {
"dataValueType": 1,
"value": "117d32f9-8275-4534-8411-1c66115ce9cd" // This is the Case Schema UId
}
}
}
}
}
}
}
}
}
}
},
"logicalOperation": 0,
"isEnabled": true,
"filterType": 6,
"rootSchemaName": "VwSysProcessLog"
}
}
}
}
]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
modelConfigDiff: /**SCHEMA_MODEL_CONFIG_DIFF*/[
...
]/**SCHEMA_MODEL_CONFIG_DIFF*/,
handlers: /**SCHEMA_HANDLERS*/[]/**SCHEMA_HANDLERS*/,
converters: /**SCHEMA_CONVERTERS*/{}/**SCHEMA_CONVERTERS*/,
validators: /**SCHEMA_VALIDATORS*/{}/**SCHEMA_VALIDATORS*/
};
});
What the filter basically does is equivalent to the following OData query:
https://my-site.creatio.com/0/odata/VwSysProcessEntity?$filter=EntityId…
Like
Hello,
Here are some community posts that cover similar scenarios related to dynamic filters and retrieving context values in Freedom UI:
https://community.creatio.com/questions/how-filter-list-page-according-current-user-contact-type-freedom-ui-0
https://community.creatio.com/questions/filtering-list-view-freedom-ui
https://community.creatio.com/questions/how-get-entity-id-module-freedom-ui-page
To retrieve the current record Id and use it in a filter dynamically, you can access the page context using:
const recordId = await request.$context.Id;
To get the Schema UId for the Case object, you can query the SysSchema table:
const schemaModel = await sdk.Model.create("SysSchema");
const schemaData = await schemaModel.load({
attributes: ["UId"],
filters: {
items: {
byName: {
filterType: sdk.FilterType.Compare,
comparisonType: sdk.ComparisonType.Equal,
leftExpression: { expressionType: 0, columnPath: "Name" },
rightExpression: {
expressionType: 2,
parameter: { dataValueType: 1, value: "Case" }
}
}
}
}
});
const caseSchemaUId = schemaData[0]?.UId;
Daiana Gavrylenko writes:
Hello,
Here are some community posts that cover similar scenarios related to dynamic filters and retrieving context values in Freedom UI:
https://community.creatio.com/questions/how-filter-list-page-according-current-user-contact-type-freedom-ui-0
https://community.creatio.com/questions/filtering-list-view-freedom-ui
https://community.creatio.com/questions/how-get-entity-id-module-freedom-ui-page
To retrieve the current record Id and use it in a filter dynamically, you can access the page context using:
const recordId = await request.$context.Id;
To get the Schema UId for the Case object, you can query the SysSchema table:
const schemaModel = await sdk.Model.create("SysSchema");
const schemaData = await schemaModel.load({
attributes: ["UId"],
filters: {
items: {
byName: {
filterType: sdk.FilterType.Compare,
comparisonType: sdk.ComparisonType.Equal,
leftExpression: { expressionType: 0, columnPath: "Name" },
rightExpression: {
expressionType: 2,
parameter: { dataValueType: 1, value: "Case" }
}
}
}
}
});
const caseSchemaUId = schemaData[0]?.UId;
Hello Daiana,
Thank you very much for your interest and your quick response! I followed your steps and the resources you provided and I managed to create the handler that defines the filter to be applied on the list:
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
{
"operation": "merge",
"path": [
"attributes"
],
"values": {
"ProcessLogList": {
"isCollection": true,
"modelConfig": {
"path": "ProcessLogListDS",
"filterAttributes": [
{
"loadOnChange": true,
"name": "ProcessLogList_PredefinedFilter"
}
]
},
"viewModelConfig": {
"attributes": {
"ProcessLogListDS_Name": {
"modelConfig": {
"path": "ProcessLogListDS.Name"
}
},
"ProcessLogListDS_Id": {
"modelConfig": {
"path": "ProcessLogListDS.Id"
}
}
}
}
},
"ProcessLogList_PredefinedFilter": {}
}
}
]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
handlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelInitRequest",
handler: async (request, next) => {
// Get current record Id
const MasterRecordId = await request.$context.Id;
// Get current schema UId
const SchemaUId = Terrasoft.configuration.ModuleStructure["Case"].entitySchemaUId;
request.$context.ProcessLogList_PredefinedFilter = {
"items": {
"masterRecordFilterWrapper": {
"filterType": 6,
"isEnabled": true,
"logicalOperation": 0,
"items": {
"masterRecordFilter": {
"filterType": 6,
"isEnabled": true,
"logicalOperation": 1,
"items": {
"entityFilter": {
"filterType": 5,
"comparisonType": 15,
"isEnabled": true,
"leftExpression": {
"expressionType": 0,
"columnPath": "[VwSysProcessEntity:SysProcess].Id"
},
"subFilters": {
"filterType": 6,
"isEnabled": true,
"logicalOperation": 0,
"items": {
"EntityIdFilter": {
"filterType": 1,
"comparisonType": 3,
"isEnabled": true,
"leftExpression": {
"expressionType": 0,
"columnPath": "EntityId"
},
"rightExpression": {
"expressionType": 2,
"parameter": {
"dataValueType": 1,
"value": MasterRecordId
}
}
},
"SchemaUidFilter": {
"filterType": 1,
"comparisonType": 3,
"isEnabled": true,
"leftExpression": {
"expressionType": 0,
"columnPath": "SysSchema.UId"
},
"rightExpression": {
"expressionType": 2,
"parameter": {
"dataValueType": 1,
"value": SchemaUId
}
}
}
}
}
}
}
}
}
}
},
"logicalOperation": 0,
"isEnabled": true,
"filterType": 6,
"rootSchemaName": "VwSysProcessLog"
};
return next?.handle(request);
},
},
] /**SCHEMA_HANDLERS*/The page schema UId is resolved perfectly with a simplified approach. However, the current record Id is not fetched properly using what everybody suggests:
await request.$context.Id;If I check the browser developer tools, I can see that the SelectQuery sent by the browser indeed uses the filter configuration, but the record Id is null:
Additionally, I am trying to make this list and filter be as generic as possible, to work on every page, so I did everything in a new Freedom UI page replacing the 'PageWithTabsFreedomTemplate' page. As you may see, the tab and the list appear in my Cases_FormPage without any issue, but the handler does not fetch the case record Id.
Why is it failing here?