How to use User association?

0
Good morning. I have an entity with an association to System.User. Upon creation of this entity (called 'Level') I need to establish the association with the application user. In the Microflow I create the record, with the following line: Member: Level.User; Member Type: System.User; Type: Set; Value '$currentUser' or '[%CurrentUser%]'. The User creates the record and displays the content of the record in a form. The association to the user seems to be empty. Any explanation on what mistake I make?
asked
9 answers
2

Could you explain your domain model a bit further? Because it is good practise not to connect directly to system.user but create an entity and set the generalization to system.user and do everything from this entity (lets call it Person). Because system.user is from the core System module and you can not edit these entities. It is even better to do the generalization to administration.account because then you can use the microflows there to create new users etc. Only do not forget when creating users that you should not create administration.account but create a new Person (which is a generalization of administration.account which is a generalization of system.user)

When you have done this make a reference from the entity Level to the newly created entity Person. This reference should be set in the microflow.

Good luck ,

Ronald

[EDIT]

So one Domain is connected to multiple Persons and a Person is connected to multiple Domains. Create a Domain view where you can manually add Persons using the reference set selector. If you want a user to 'subscribe' to a Domain you can create a button with a custom microflow to add this users to the reference set.

answered
0

Hi Ronald, every Activity in my system will be part of a Domain. A Domain is shared between several Persons. The Activity can be viewed (and updated) if the current user is one of the Persons that links to the Domain (of the Activity). For me it is unclear: - when adding a Domain it should at least be linked to the Person representing the User the user that adds the Domain - how? - when selecting Activities on a form only Activities have to be selected that are linked to a Domain, that is linked to the Person representing the current user - how? Thanks!

answered
0

Hello Ronald, OK I will edit the original question. Still I do not know whether you exactly understand my question. I need to find out what Person is signed on to the application (via System.User?), to find the Domains he is authorized for. Quiestion is: how to select the Person (using the System.User?)? I can't figure it out in XPath. Also when creating a new Domain, I need to at least assign the Person linked to the current user. Can't figure out how to do that in a microflow Create action...

answered
0

Gerard

If you want to find the current logged in user in a microflow, you can use a retrieve action as follows:

  • retrieve from any user entity (you could start with System.User or Administration.Account)
  • use the following XPath: [Name = $currentUser/Name] This works because Name will be an attribute of all user objects that are inherited from System.User and $currentUser is available in all microflows and contains the current logged in user.
  • Use an inheritance split to determine what type of user it is. Once you have determined this, continue on with what you want to do

Hope this helps.

Mike

answered
0

So I changed everything like suggested. Thanks. I have an entity Person not linked to a System.User, with a 'Name' filled which is always the same as the Name in System.User. Now the only thing I need in some forms is a selection on all Persons that have a name that matches the Name of the current user. I tried ".../Person/Name = '[%currentUser%]/Name'". It does not work. Can anybody tell me how to do this? Please do not say there are better solutions, they all do not deliver the result I want. Thanks!

answered
0

Try using the Administration.Account entity. But if you insist on using a different one, then it should be a specialization of the System.User. This is so you can retrieve (or cast) to the appropriate entity type.

You can retrieve it by simply using ['[%CurrentUser%]' = id] (grids) or in a microflow [$currentUser = id]. You can also cast the general entity in a microflow to a specialization.

When retrieving data in XPath for a data grid, you can never add on to the tokens. For example, [%CurrentUser%]/Name is invalid. Mendix does a replace on all of these tokens, so they're not evaluated in quite the same manner.

If you need to link something in a data grid to the currentUser, any of these are valid:

[Employment.Job_Account = '[%CurrentUser%]']
[Employment.Job_Account/Administration.Account = '[%CurrentUser%]']
[Employment.Job_Account/Administration.Account/id = '[%CurrentUser%]']

The same goes for microflows, but instead you'll use $currentUser.

Here's some XPath/Token reference material:

https://world.mendix.com/pages/releaseview.action?pageId=3736911
answered
0

Thanks for Your answer. Slowly approaching my goal, but not reached it yet. 1. I need a list of Persons, some of them are linked to a System.User with the PersonUser association, some of them are not linked (generalization is not a solution). 2. When a User signs in the first time a microflow creates a Person that should have a link. Using a 'Create' on Person. The Person name is filled from $currentUser/Name: OK. The association is set to $currentUser. 3. When viewing the Persons generated on a form PersonUser/User/Name does not show anything. It seems to me the association is not set. Why and how?

II. Then I remove the association and store the User/Name in an attribute of Person (called 'PersonUser'. Upon creation of the Person in the startup microflow I like to fill the FullName from the System.User - how? I only see the Name and the Password. Now in an Xpath I only need the current logged-on user. Like '[PersonUser = $currentUser/Name]'. How do I retrieve the logged-on user Name in an Xpath without having a real association?

III. So some Persons are a specialization of User, others are not. Any advise on this?

You see still some questions left...

answered
0

Thinking about it, I could solve all these having a (session) variable only applicable to the current user, and fill it in the startup workflow with the UserName or the current user id. This variable has to be used in microflows and xpath's. Is this possible...

answered
0

It works. However I expect it to be very inefficient. But it works...

remove all associations with System.User extend Person with 'Person_User', not a real association but an attribute that contains the User Name extend every microflow that needs this relationship with an action finding the current user name via $currentUser/Name use this as a selection criterium in every microflow accessing Person replace all applicable form data sources by microflows that include the selection on Person. Pfff. Thanks for all Help. Any suggestions NOT including an association to System.User stay welcome (e.g. like using a session variable).

answered