Hi everyone, first post in the Community.I have a default filter on a record type:
a!queryFilter( field: "createdBy", operator: "=", value: loggedInUser(), applyWhen: not( isusermemberofgroup(loggedInUser(), cons!MY_ADMINISTRATOR_GROUP) ) )
The idea is that administrators can view all entries, while regular users can only view entries that they have created.Filter works fine in the record grid view, but breaks the Summary view upon clicking on a record, with the following error:
An error occurred while retrieving the data for “MY_DATATYPE”. Details: Unexpected error executing query (type: [...], query: [Report on Record Type], order by: [[Sort[id asc]]], filters:[((id = TypedValue[it=1,v=1]) AND null)]) (APNX-1-4205-003)
It is evident that the issue is due to the use of the applyWhen parameter (remove it and the problem disappears), but I can't figure out why.So, questions:
1) What is the cause of the problem?2) How can I fix it?3) Is there a better why to achieve what I'm trying to do?
Thanks in advance.
Discussion posts and replies are publicly visible
Try converting the user to text, tostring(loggedInUser()).
Try with If condition instead of applywhen.
Does not work.
Why? And how would I do that? The filter expression editor asks for a queryFilter.
Hi,
A basic user is not allowed to know whether another user is a member of such groups.
so you need to create a custom logic to check if the loggedIn user is the member of group or not.
Use below logic
contains( a!groupMembers( group : cons!MY_ADMINISTRATOR_GROUP, direct : true() ).data, loggedInUser() )
ThanksVinay
If I try to use your code in the "applyWhen", it breaks. Aside from that, I don't really understand the logic, which seems equivalent. Also, in my tests, I am administrator, and the record grid works fine both as admin and regular user. It's the Summary that breaks, and it always breaks regardless of me being admin.
Purely for troubleshooting purposes - does the problem still happen when you hardcode the value of applyWhen? For example, set it to applyWhen: true() and test, then set it to false() and test.
At a glance - 2 points:
As per my understanding the issue is with applywhen when you use only one queryfilter as it is returning a null value instead of empty filter {} when the applywhen is false.
For a workaround you can use the if condition as below.
if( isusermemberofgroup( loggedInUser(), cons!MY_ADMINISTRATOR_GROUP ), {}, a!queryFilter( field: "createdBy", operator: "=", value: loggedInUser() ))
Or you can use queryLogicalExpression function as below
a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter(field: "createdBy",operator: "=",value: loggedInUser() applyWhen: not( isusermemberofgroup( loggedInUser(), cons!MY_ADMINISTRATOR_GROUP ) ) ) })
Thank you, very clear explanation. The problem is now solved and I understand the cause.