Getting the Logged in user as a parameter

Originally Posted 14 March 2014, 9:39 am EST

  • Originally Posted 14 March 2014, 9:39 am EST

    In a report there is a way to get the ID of the current user with this function:


    This is great for queries, but makes it hard to preview a report. I was attempting to make a report parameter that has this expression, so in preview it will return nothing and the developer can enter an id, but when deployed to ARS it will get a value and filter the report correctly.

    Has anyone gotten this to work? The goal is to be able to have reports using this technique to work for in development and production modes.
  • Reply


    As per my understanding of the issue you are trying to maintain the session of the already logged-in user and pass the id of the logged-in user as the parameter to show the respective report :

    To implement this, you need to create a CustomSecurity Provider. In the CustomSecurity Provider, you will have to create a security token using CreateToken method, that the server holds to identify the current logged in session with username and password parameters, as well as a custom parameter for any other credentials data used by the provider.

    In this CreateToken, you can pass credentials of logged user using session variables and assign it to the security token.

    You may also refer to the following blog link which discusses about custom authentication:

  • Reply

    You kind of missed the point of my post. I have a CustomSecurity Provider set up and have the report working correctly in a multi-tenant mode. However, this is not previewable at design time because you need a hard coded value for the Id rather than the tenant expression above.

    I am trying to find a way for these reports to work both at design time and at run time.

    My thought was to have an Id field with two possible values like so:

    LoggedInUser: =Code.UserContext.GetValue("UserId")
    DevUser: 45902

    At design time, during preview, we would pick the DevUser. At runtime, we would make this field hidden so the first value, LoggedInUser, is used.

    However, the problem is deeper than this. Regardless of what technique we use, it appears that at runtime, the =Code.UserContext.GetValue("UserId") expression does not work as a report parameter value.

    This is an issue because I have another dropdown report parameter called "client" that depends on this being populated. So the user can choose their client based on who they are.
  • Reply

    In the VS IDE or stand-alone designers for ActiveReports 8, you do not currently have access to the security provider configured on the ActiveReports 8 Server. So when you preview the report in these designers, you will not get a value for the UserContext (in your case the UserId).

    However a basic IIF condition should help us check the output and substitute the value. Have you tried to use an expression like this:


    The DevID here would be your default ID that you want to use at design time for these AR reports.
  • Reply

    Clever Bhupesh.. I gave it a try. IsNothing didn't work, but this version did (in designer mode):

    =IIF(Code.UserContext.GetValue("UserId") = null,"AB9BEAD3-1032-41F1-8CBB-ECC06752C2DC",Code.UserContext.GetValue("UserId"))

    However Code.UserContext.GetValue("UserId") still returns null when used as a report parameter expression when hosted in ARS. So deployed into ARS, I get the Dev user id as the parameter, which doesn't map to a real user on production.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels