Use logged in user id for filtering in Portal 2

Hi!
I’m new here and new in the novacura sphere overall!

We are building a portal where our users are supposed to get an overview of orders assigned to them and their colleagues in form of a schedule portlet. We had a vision of being able to use the information regarding who the logged in user is to filter the schedule so that it only shows the orders belonging to the logged in user directly when signed in. After that the user can use the filter to show others or all orders. But we can’t seem to find a way to get the information regarding userid of logged in user.

Has anyone else made something similar? Is it even possible?
Please help!

Hey annie,

i have to check if there is anything different in the scheduler portlet, but are you using a workflow as datasource?
If so that flow should be run with the Portal user and you can use the global userId (it’s there by default as an available variable in every workflow) in the workflow for filtering data.

If you then want to show additional orders there are plenty of possibilities. For example a filter portlet with a parameter to show all that gets passed to the datasource workflow. when fetching data the condition would then be something like "where user = userId OR MyFilterParameter = ‘ShowAll’ " (of course replaced with however you name your variables). Alternativly it could also be a simple button that sets a user variable on the Flow Server and you can query that in the user workflow (similar to the UserId).

Try it out and let us know if you are stuck anywhere :slight_smile:

Best Regards,

Johannes

Hi!

Thanks for such a fast answer! I should probably be more thourough. So the scheduler fetches the data straight from the database, so no workflow there. But each record of the database has a reference to a user id. We have set up a filter with a searchfield where you can search for an id and thereby filter the orders and it works fine. We tried to do a checkbox for all orders/only my orders to be able to filter it from the start. We tried doing it similar as we would do in studio but trying to use the global variable for user id only gave us the answer that it was running as NOVAFLOW user i think. All the data sources for the portal is strictly DB, no workflows at all, but the user will log on to the portal so I figure there must be a way to fetch the id? Sorry if i’m messy in my explanation, I have only worked with this for like a week. I usually develop in Microsofts power platform :sweat_smile:

Can you try using :userId or {userId} in the DB query and see if it works? Since a while we in our Team only use workflows as a data source. It’s a tiny bit more bothersome to setup, but just gives you more options. In general i would recommend using that, but be warned that it would take some getting used to :slight_smile: . Still i think one of the 2 options above works in Portal queries if i remember correctly.

The userId Variable should always show your logged in User, not some admin user.

Second alternative (at least if your system is IFS) would be to get the DB User via e.g. fnd_session_api.get_user_id (i think, if not exactly that command it’s similar. There are different get functions. You might need get_web_user depending on how you setup your users), but that would require a personalized connector where you login as the actual user, not some generic admin user. I unfortunatly don’t know your setup so it’s a bit hard to give the right advise :slight_smile:

/Johannes

Hi, ‘:UserName’ is used in the portal to get the id of the logged-on user when having database as the data source.
For example: Select * from table where CreatedBy = ‘:UserName’

Hi,
We usually use User properties for this kind of direct filters.
Where you could set a user ID that is used in your ERP if it differs from the Novacura name.

These are available to you if you use workflow as a source and run your querry in that instead.
If you use a workflow you can all sorts of logic to when and what to run in your querry.
But like Johannes says it takes some getting used to.

Br Johan W

Hi everyone!

I tried your suggestions Johannes but it did’nt work for us! We are using IFS as you guessed, and our next option would be to go through a workflow instead. But we will definitely try Olas suggestion as it seems to be what we are looking for! I will let you know after we tried it! @OlaCarlander are all these secret little nuggets documented somewhere or is it learning by doing? My colleagues mostly work in flow studio so they are used to the enviroment but it seems that some variables are different (as expected of course). @WibjerM3CS thank you for your answer, our user id from the ERP is the same as our user name in Novacura, I was oblivious enough to think that it was standard, but you learn something new each day!

Thank you @OlaCarlander , that was exactly what we were looking for!

So now to my final question, so I know that the checkbox filter filters on boolean values and that the operator type is equals. Does this mean that I can only filter on columns that have the values true or false?

What we are trying to do is to have checkbox and when it’s unchecked we wanna display the orders where the logged in user (‘:UserName’) matches a field on the order, and when it is checked it’s supposed to display all orders.

So I tried to do a case in the where clause like:

where case
when WORK_MASTER_SIGN like ‘%’ then 0
when WORK_MASTER_SIGN like ‘:UserName’ then 1
end = 0

This works but I hoped that I was gonna be able to change the 0 and 1 to what ever boolean value the checkbox wants (which is what exactly?) and then add my checkbox parameter as a listener as of: end = {ALLORDERS}.

I’ve tried this with values such as: true/false, True/False, TRUE/FALSE, $true/$false, 1/0, checked/unchecked etc. But nothing works, so either I’m doing something wrong or is it not possible?

Glad to hear! About the secret nuggets I would recommend the portal training where different scenarios and how to understand and track the mechanics are covered.

It’s hard to tell exactly what you need but the passed variables from the boolean should be true / false. It is visible if you trace the network in the browser’s developer tool

I think you got the “case when”-code down, so I think the above is what you need. Remember the listener has to be of the onRowSelected type

Thank you! That did the trick.

I do have one more question though, the checkbox filter is supposed to be boolean, but for me it has the values true, null, false (we do have an older version of portal2 and are going to update it later today, maybe it’s already been fixed?). If not I think it should be as it is not very user friendly (or developer friendly)! I’ve heard about another forum for ideas, maybe it is a better topic for that forum? :slight_smile:

Haven’t thought about that myself, but yes it seems to have a null state as well when used in the filter.
Can be good or bad I guess for different scenarios (It has, it doesn’t have, or I don’t know sort of thing).
Workaround solution: case when null or false then false. But still gives the user three states to choose from of course.
I think so yes, ideas.novacura.com and add it as a feature request over there.

True! Thank you for all your answers!