Hi Everyone,
I am saving value of loggedinuser() function into cloud mysql db, but everytime it saves the "Administrator" instead of the my username. I test this function in expression rule where it gives my username.
Can anyone please help me out?
Discussion posts and replies are publicly visible
Hello shubhamy0005,
Can you show us your code where you are giving the loggedInUser() value.
also try to provide a little more info such as images
can you please check if you are overwriting your field in any script task in a process.
Thanks Harshita, But it is not overriding anywhere.
In the script task inside process model I am using loggedinuser() function and then saving it in db variable before being used in write to datastore entity.
Hi,
This is normal behavior. If there is no user context, the function will return the "administrator" value. See below the extract from the documentation:
It is only applicable in situations where there is a user context, such as when rendering an interface, displaying a report, or executing a process task form. If there is no user context, such as when used in an expression in a node output, loggedInUser() returns "Administrator".
It highly depends what user you are trying to save in the db - is it the user that initiated a process or a user that acted on a process task? If it's the first, just use the pp!initiator parameter, if it's the second use the tp!owner parameter populated after a user task.
As Alex Boerescu mentioned you can use the pp!initiator, it will resolve your issue if you are writing it from the script task. You cannot achieve your requirement with the loggedInUser() because it doesn't have a context. You need to follow what Alex has suggested.
Thank you Alex, it worked now.