Timeline Filter for "Owner" - Restrict to only Contacts with a User record?
Is it possible to restrict the "Owner" filter for Timeline components to only show Contacts which match a specific filter condition? We are currently seeing every Contact as an option, but for us this should be restricted to only Contacts which have a User record associated with them, and ideally we'd want to add some more customisation to the filter options beyond this.
Like
I've discovered that it's possible to add this using code. To do so, you need to override the crt.LoadDataRequest handler and use the following code:
{ request: "crt.LoadDataRequest", handler: async (request, next) => { // Filter Timeline's Owner filter to just Contacts with a User record if(request.dataSourceName === "ByOwnerQuickFilterInTimeline_xi3lpgm_ComboBox_List_DS") { const filter = new sdk.FilterGroup(); await filter.addExistsFilter("[SysAdminUnit:Contact:Id].Id"); // workaround for filters const newFilter = Object.assign({}, filter); newFilter.items = filter.items; request.parameters.push({ type: "filter", value: newFilter }); } return await next?.handle(request); } },
You have to replace the name of the Timeline component in the above code from Timeline_xi3lpgm to whatever the component is called on your page.
Thanks Bogdan, it's definitely a feature that's needed - having every Contact show up in the Owner filter with no way to change this on a CRM platform isn't ideal.
I've discovered that it's possible to add this using code. To do so, you need to override the crt.LoadDataRequest handler and use the following code:
{ request: "crt.LoadDataRequest", handler: async (request, next) => { // Filter Timeline's Owner filter to just Contacts with a User record if(request.dataSourceName === "ByOwnerQuickFilterInTimeline_xi3lpgm_ComboBox_List_DS") { const filter = new sdk.FilterGroup(); await filter.addExistsFilter("[SysAdminUnit:Contact:Id].Id"); // workaround for filters const newFilter = Object.assign({}, filter); newFilter.items = filter.items; request.parameters.push({ type: "filter", value: newFilter }); } return await next?.handle(request); } },
You have to replace the name of the Timeline component in the above code from Timeline_xi3lpgm to whatever the component is called on your page.
Harvey Adcock,
good find, thanks!
You should mark your own answer as solution ;)
Harvey Adcock,
Well done! Thanks for sharing this Harvey.
Also, if you've moved to 8.1.1 you no longer need the filters workaround - it's finally working properly in 8.1.1, just thought I'd mention.
Ryan
Ryan Farley,
Ahh great to hear, thanks for the info Ryan - and thanks for spreading the info about that workaround in the first place!
I'd like to share my solution on lookup filtering.
We wanted to have only contacts from our company and in certain functional role.
{ request: "crt.LoadDataRequest", handler: async (request, next) => { if (request.dataSourceName !== "FbContact_List_DS") { return await next?.handle(request); } const ourCompanyFilter = new sdk.CompareFilter( sdk.ComparisonType.Equal, new sdk.ColumnExpression({ columnPath: "Account.Type" }), new sdk.ParameterExpression({ value: Constants.AccountType.OurCompany }) ); const funcRoleFilter = new sdk.CompareFilter( sdk.ComparisonType.Equal, new sdk.ColumnExpression({ columnPath: "[SysAdminUnit:Contact:Id].[SysUserInRole:SysUser:Id].SysRole.Id" }), new sdk.ParameterExpression({ value: Constants.FunctionalRole.MyCustomFunctionalRole }) ); request.parameters.push({ type: sdk.ModelParameterType.Filter, value: ourCompanyFilter }); request.parameters.push({ type: sdk.ModelParameterType.Filter, value: funcRoleFilter }); return await next?.handle(request); } }
Alex Zaslavsky,
Interesting, it hadn't occurred to me to push multiple filters to the parameters. I've always added the multiple filters to a FilterGroup and then added the group to the parameters. I guess it's an array for a reason :) Nice to know it works that way as well.
Ryan
Hello ,
Can we set a current user as a default in timeline quickfilter ?