Support Topics Documentation Slack YouTube Blog

"Get current user" is changing (but should not)

I’m using a form in UI Builder to let users update their user name. In the users table, “email” is the identifying element and I’ve configured “name” with the “unique value” constraint.

When I’m updating the users table with an already existing name, an exception is thrown, which is correct. However, after that, the codeless block “Get current user” returns the invalid user name.
My expectation is, that the “Get current user” still contains a consistent state as defined by the database table constraint. Do you agree?

Here is my form submission logic:

Regards,

Hello @Klaas_Klever

If I clearly understand what you mean - when you try to update existed user, backendless throws an exception, but the user was updated.

Also, could you provide your app id to saw how this code works in your app?

Your understanding is correct (the users table is not updated but the internal runtime representation of the current user).
The code shown is the submit event for the form on page “account”.
My appId is 5BDF0E64-9F03-6F8E-FF75-0E183AF61100
Regards,

Hello @Klaas_Klever

When you set “get current user” to desiredUser, you are actually passing a reference to an object.
And desiredUser is the “get current user” actually. Thats why, when you change something in desiredUser it is changing in “get current user” too. This is a property of the engine that the codeless is running on.

To get predictable behavior you should make a copy of object.
Here is one of ways.

Regard, Viktor

I see. This is a very important information, that object assignments are references.
Will try your approach.
Thanks

One thing though: “Get current user” sounds like a function returning the currently logged in user.
It seems, that this is not true, and “Get current user” is just an object which has been filled at some point in time, correct?
Regards

@Klaas_Klever

Yes, you are absolutly right.
This method doesn’t make new request every time it is called. It’s called once and next time use result of first call

Regard, Viktor

Hi @viktor.liablin ,
I’m still struggling with the semantics of “Get current user” …
If I’m changing the users table using the block “Update User”, the object “Get current user” still reflects the old state before the update. Thus, “Get current user” is inconsistent with the users table.
In my opinion this is a bug. All successive uses of “Get current user” return the wrong result. If you offer a method “Update User”, this method should change the result of “Get current user” accordingly. Otherwise, I have to adapt the object “Get current user” by myself with the wierd statement Set property in: (Get current user) property ...

So my request is: The method “Update User” should adapt “Get current user” accordingly, if the update is successful.

Regards,

@Klaas_Klever

Thanks for reporting this issue.
I’ve create an internal ticket BKNDLSS-24845, to discuss this issue with the team.

Regarg, Viktor

Hi, @Klaas_Klever

We’ve just updated cloud servers with a fix for the issue you described above. Now the Get Current User block has the reload checkbox which will help you to display updated data. Could you kindly let us know whether fix works for you well?

Regards,
Marina

Hi Marina,
I’ve found this feature already :grinning:
Yes. It’s a working solution.
Regards