Table filtering according to current user info

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
ahmed7
User
Posts: 100

Table filtering according to current user info

Post by ahmed7 »

hello
I use asp.net make 2021
and want to get data from table according to current user info such as (currentuserid()) and so on.
I try many time in filer editor/table option and no record output .
please am really need to help
Thanks


MichaelG
User
Posts: 1111

Post by MichaelG »

Show your table filter.


ahmed7
User
Posts: 100

Post by ahmed7 »

MichaelG wrote:

Show your table filter.
"Sub_dept_ID= CurrentUserID()"
or
"Sub_dept_ID= 'CurrentUserID()'"

this the filter which has written in the table filter editor
Sub_dept_ID : is the field name (integer)

when I use :
"Sub_dept_ID= '1'" will work fine because i put constant , but when use current user id or something else so nothing output

thank you dear


ahmed7
User
Posts: 100

Post by ahmed7 »

"Sub_dept_ID= CurrentUserID()"
or
"Sub_dept_ID= 'CurrentUserID()'"

this the filter which has written in the table filter editor
Sub_dept_ID : is the field name (integer)

when I use :
"Sub_dept_ID= '1'" will work fine because i put constant , but when use current user id or something else so nothing output

thank you dear


MichaelG
User
Posts: 1111

Post by MichaelG »

You should concat the function as:

"Sub_dept_ID= '" + CurrentUserID() + "'"


ahmed7
User
Posts: 100

Post by ahmed7 »

Thank you so much , its working


ahmed7
User
Posts: 100

Post by ahmed7 »

So If I want to add more than one filter ?
how can do that?
I mean two fields for two current user info with (or)

Thanks


MichaelG
User
Posts: 1111

Post by MichaelG »

You should construct your SQL as:

"Sub_dept_ID = '" + CurrentUserID() + "' OR Sub_dept_ID = ..."

If ... is a server side function, concat it similarly to CurrentUserID().


ahmed7
User
Posts: 100

Post by ahmed7 »

Thanks Dear


aspsteve
User
Posts: 52

Post by aspsteve »

I have a related question and I am trying to filter the displayed dropdown value based on the user level

See my syntax below. Please recommend any edit as this is not working.

If '" + CurrentUserLevel() + "' = '4'
Then
"Request_Status IN ('Pending Approval','Submitted For Approval','Cancelled')"
ELSE If '" + CurrentUserLevel() + "' = '5'
Then
"Request_Status IN ('Submitted For Approval','Released For Payment','Cancelled')"
ELSE
"Request_Status IN ('Pending Approval')"


MichaelG
User
Posts: 1111

Post by MichaelG »

Use the ?: syntax. For example:

CurrentUserLevel() == 4 ? "filter1" : (CurrentUserLevel == 5 ? "filter2" : "filter3")


aspsteve
User
Posts: 52

Post by aspsteve »

I updated as instructed below

CurrentUserLevel() == 4 ? "Request_Status IN ('Pending Approval','Submitted For Approval','Cancelled')" : (CurrentUserLevel == 5 ? "Request_Status IN ('Released For Payment','Submitted For Approval','Cancelled')" : "Request_Status IN ('Pending Approval')")

and now I have the following errors

C:\inetpub\wwwroot\staging_publishing\*\Models\*View.cs(2220,46): error CS0019: Operator '==' cannot be applied to operands of type 'string' and 'int' [C:\inetpub\wwwroot\staging_publishing\*\*.csproj]


darkdragon
User
Posts: 150

Post by darkdragon »

since ANM2021, CurrentUserLevel() returns a string.

CurrentUserLevel() == "4" ? ...


Post Reply