How to filter by current user on a service portal simple list widget

PranavSuj96
Mega Expert

Hello, 

 

I want  logged in user in my service portal to be able to see records from custom table if  the customer name matches theirs.  I added a simple list widget to my homepage and under the filter field I wrote this:

 

customer_name=javascript:gs.getUserID().

 

Is this correct? When I try applying this filter on the table in my instance the filter comes up as customer_name=(empty).

1 ACCEPTED SOLUTION

You know what I can think of a few issues might be the case,

 

First you gotta determine where is the filter being applied, on server side or on client side.

On server side gs.getUserID() is what you want, but that needs to be applied before query.

On the client side get user ID is a different framework, it's definitly not gs.getUserID(), i forgot off top my head the syntax.

 

Also you said this is a widget so you can take a look at the widget itself and determine if the filter is server side or client side.

 

Edit: 

 

Quick googling tells me client side is actually g_user.userID

View solution in original post

5 REPLIES 5

Yifeng Zhang
Mega Expert

gs. getUserID() returns the user's record sys_id

 

so if your customer_name returns the name of the user, it's no good.

 

It must be the reference field that contains the sys_id, and always use sys_id.toString() or getValue("u_user_reference") otherwise you might get an object that is not string so the comparison always fails.

 

I haven't tried it directly in the UI filter, but you probably need the javascript:gs.getUserID()  to tell the interpreter to evaluate that instead of taking it as a string.

 

EDIT: never mind you are already using it. Then it suggests the gs  object is not defined.

You know what I can think of a few issues might be the case,

 

First you gotta determine where is the filter being applied, on server side or on client side.

On server side gs.getUserID() is what you want, but that needs to be applied before query.

On the client side get user ID is a different framework, it's definitly not gs.getUserID(), i forgot off top my head the syntax.

 

Also you said this is a widget so you can take a look at the widget itself and determine if the filter is server side or client side.

 

Edit: 

 

Quick googling tells me client side is actually g_user.userID

Ohhhh that makes a lot of sense! Thank you very much 🙂

😄 you are welcome