How can I receive additional field about the logged in user
Question
Application Type
Reactive
Service Studio Version
11.51.8 (Build 58407)

Hello friends,

I'm new to OutSystems, so forgive me if the answer is obvious. I want to receive additional information about the logged in user, in addition to the output of getuserID(). 

I have extended the built in user entity and made a 1-1 relationship with the user_attributes entity. In that entity I have a field, named OfficeID and I want to be able to receive that OfficeID of the logged in user with a function similar to getUserID(). In other words how can I establish a mechanism that will give me the OfficeID of the logged in user, like getUserOfficeID()


Thanks in advance.

Solution

Hi

create server action in the same entity module e.g Call "GetUserOffice()" in that action use the aggregate to filter and get the office detail. make the server action a function and public by selecting yes in related fields


mvp_badge
MVP
Solution

I think okan wants a client action, not a screen action, that does this. And the simple answer is: that is just not possible. Of course, what you could do, is change the login logic to retrieve the user office ID, and put it in a Client Variable. Afaik that can be used inside a function.

Solution

So you need to call the server action that retrieves the officeId and with that output, you assign the value to the client variable.

What I did here was put everything in a server action and retrieve all the data I want.



Now you need to figure it out by doing step by step.

1- get the office id

2- call the action that retrieves the office id upon login

3-assign the officeid to the client variable

Solution

Hi

create server action in the same entity module e.g Call "GetUserOffice()" in that action use the aggregate to filter and get the office detail. make the server action a function and public by selecting yes in related fields


You can create your own function either client or server action and you can establish it as a function. This should be done in a core module where you can expose to other modules but anyway this should be done where you have your core services.

Kind Regards,

Márcio

Thank you for your answers, both do the job when I create a server action. Now I want to do something similar with a client action. I want to enclose a button in an "If" clause and want to do the same check. I create a client action and use the server action I created with that client action. 

But I get the following error: "Invalid Client Function 'GetKullaniciYetkisi' cannot be used in 'GetYetkiID' because server actions are not available in client functions. Change the 'Function' property of the action 'GetYetkiID' to 'No'." And when I change the function property of the server action in to "No", obviously I can not see the client action in the if clause. 

Can you please tell me what I'm doing wrong

You cannot use server actions in client function actions. So what you need is to use that server action in a data action and do all the calls for that action or function on the server-side. That way it will work.

https://success.outsystems.com/Documentation/11/Developing_an_Application/Implement_Application_Logic/Actions_in_Reactive_Web_and_Mobile_Apps?_gl=1*1uv32xx*_ga*MTY4ODA4MDcwNC4xNjMzMDc3Njgw*_ga_ZD4DTMHWR2*MTY0NjIxMTA1Mi4xLjEuMTY0NjIyODkzNi42MA..

Kind Regards,

Márcio

So How can I use it in an "If" clause

I already said. Use a data action on your screen, put as  output a boolean that will return the result from that server action. Then you can use the output of the data action on that if.

Kind Regards,

Márcio

mvp_badge
MVP
Solution

I think okan wants a client action, not a screen action, that does this. And the simple answer is: that is just not possible. Of course, what you could do, is change the login logic to retrieve the user office ID, and put it in a Client Variable. Afaik that can be used inside a function.

Yeah, I understand, that is another way of doing and I think you will just do that once, so I think that's the best course of action. My idea was to call every time you need that info to call the server to get the office id. It's not wrong, but you can avoid those multiple calls by putting just once inside of a client variable as you said when you do login. :)

And what about this?

Do you think saving an id in a client variable is the best thing?

mvp_badge
MVP

Yes I do. The alternative is to have every screen where the Id is needed retrieve the Id and store it in a local variable. Of course, I'm assuming the ID isn't top secret, and can't be abused.

Yeah, I don't know, from past experience I was taught that that is not the best thing, at least it should have another layer of security like a token. But of course, Okan is learning and I don't know how good is to push all this information. For that, I would advise @okan yucel to do at least the training to know all these terms and get some practice before starting something more "complex".

I'm only using this operation to hide or show buttons. Sensitive part is done on the server side logic so this shouldn't be a problem

So you should go with @Kilian Hekhuis's answer by using client variables. :)

When you do log in, after doing login, on the login action you should call that info and assign the value to the client variable.

I just can not find how I can create a data action

Screen Shot 2022-03-02 at 4.54.53 PM.png

mvp_badge
MVP

You don't need a data action, you can also have a screen aggregate. But then still, you'd need that in every screen. My solution above would allow you to only retrieve it once.

I would love to use your solution Kilian, I just don't exactly know how to do it since I'm new to terminology.

 I believe the client variable is "Local variable" right?

If so, I don't know how can I assign my officeID to that variable in the login logic. 

I would be grateful if you can guide me

mvp_badge
MVP

No, Client Variables are equivalent to the Traditional Web's Session Variables. They can be found on the Data tab, between Structures and Site Properties. If you create a new Reactive App, Service Studio automatically creates a Username Client Variable that it sets in the Common/UserInfo Block. It's something similar what you can do with the office ID.

Yes I found the client variable and added it, can you please tell me how I can place that value in the client variable upon login?

Solution

So you need to call the server action that retrieves the officeId and with that output, you assign the value to the client variable.

What I did here was put everything in a server action and retrieve all the data I want.



Now you need to figure it out by doing step by step.

1- get the office id

2- call the action that retrieves the office id upon login

3-assign the officeid to the client variable

Works like a charm, thank both of you for your help

mvp_badge
MVP

You're most welcome, happy coding!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.