Skip to main content
January 10, 2023
Solved

Issue while saving loggedinuser()

  • January 10, 2023
  • 7 replies
  • 0 views

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?

    Best answer by alexandru.boerescu

    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.

    7 replies

    konduruc733182
    January 10, 2023

    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

    January 10, 2023

    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.

    konduruc733182
    January 10, 2023

    As alexandru.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.

    January 10, 2023

    can you please check if you are overwriting your field in any script task in a process.

    January 10, 2023

    Thanks Harshita, But it is not overriding anywhere.

    alexandru.boerescu
    January 10, 2023

    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.

    January 10, 2023

    Thank you Alex, it worked now.