16
Views
4
Comments
Solved
How to retrieve current user loggedin and connect it with an entity
Question
Application Type
Mobile

Hi Guys,

I am facing a logical issue with one of my integration. Below is my usecase

I have an Entity "Client" with clientId as identifier and Client Name etc. Each of these clients are given access to login to the app. So for that i went to the Users page and created a user for each client.

Now in my app, i am trying to retrieve which user has loggedin by using GetUserId()  function and referencing this with the identifier of Client entity. But when i test this, GetUserId() is retrieving value as 5 and my Entity has 1 as the value for the corresponding Client.

Clearly i havnt established a proper connection between the identifier in the Client Entity and the users that are created.

So i want to understand what is the right approach to create a new client so that this getUserId() correctly points to the identifier of Client Entity. Also if i want to create 100 clients in one go, can i still active this integrity?

Appreciate your help.


Thanks

Shiva

mvp_badge
MVP
Rank: #75
Solution

You're welcome, Siva 

Glad to help you :)

If the posted solution helped you, could you please mark it as a solution. It really motivates :)


Kind regards,

Benjith Sam

Rank: #89

Hi Siva,

when you create client entity use one UserID attribute and when you create  user for each client provide this user identifier in UserID attribute.

So your problem will be fixed.

or 

Use user id identifier as client id identifier when you create a user same data insert in client entity.


Hope this will help you.

Regards

Rahul

mvp_badge
MVP
Rank: #75

Hi Shiva,

Please refer to the below-mentioned reason with regards to the observation which you had.

  • The primary key attribute i.e. Id attribute of an Entity does have a property called Is AutoNumber of which the value is set to Yes by default i.e.  Is AutoNumber = Yes
  • As the User entity is a system entity, it is prefilled with some systems users. Hence the latest/last UserId value would be other than the initial value i.e. 1
  •  Client Entity is a newly introduced entity, of which the primary Id attribute value starts from 1 because of this very reason the UserId value and the ClientId value won't match.
  • In order to handle such a situation, you can define a relationship between User Entity and Client entity by defining the UserId as the FK in the Client entity as shown below.

  • The new Client creation flow would be - First Create the UserRecord in the User system entity -> then Create the Client Record in the Client Entity, referencing the UserId FK attribute generated from the User record creation. 
  • Also, introduce some client pre-existing checks in the client creation action to avoid duplication of client/user records.


Hope this helps you!


Kind regards,

Benjith Sam