User variable repeated for all pages

Hi,
I need to use a “User variable” in the header of the report, so to be repeated for all pages.
I have used a tex box like “Name:” and a user variable like “@userName” with the value of the user name.
This variable is taken from a table available in the datasource of the report, that contains many fields including the user name.
In Layout Preview I saw something like “Name: Mickey Mouse”, then I assigned both text for all the layers, but in the Preview I just see “Name:” and the variable content is empty.
What I’m missing?

Thanks

I noticed that if I add a Report Parameters with the value included in the same table as the User Variable, I can see the “@userName” correctly in all pages in Preview.

Hi Ivano,
if you assign a value from the table to the user variable, you must ensure that the text object used is printed after the table or report container.
See image:

If you don’t use databinding you would have to link (Sequential) the text object with the table.

Hi Erdal,
I’ve tried in this way but it doesn’t work. I cannot see the @userName in the Preview (just in the Layout Preview)

Could you please answer the following questions, thank you.

  • Do you have the real data preview in the designer?
  • Which development environment do you use to develop it?
  • Is it visible when you print it correctly?

Maybe it helps that you upload the used project file.

I found the issue: since I have a lot of table from datasource I was not using the table with the user variable.
Inserting this table with empty lines (so is not visible), I’m able to correctly visualize the user variable.
Thanks

1 Like

I have another question regarding this topic:
In the table I have many users, and in the @userName variable I would like to insert some condition to visualize it.
For example if I have a field, in the Users table, that contains the city of the user, and I have a variable (passed from the C# code) tha is called “myCity”. I would like to view the @userVariable value when the following condition is true:
Users.City == myCity
Example:
DB Table “User” contains
immagine

“myCity” = Oxford

so I want to get the name “John” as value in the @userName

It is possible?

You could use the variable “myCity” for the table “User” in the filter, then the table would show only this record and the @userVariable would contain the needed value.
e.g.
User.City==myCity

Whether this is optimal for the performance, would change depending on the datasource (number of records etc.), it would be optimal of course if you could define the filter already in your application.

Another possibility would be to work with SetVar() and GetVar().
Workflow:
Add the content SetVar(“userVariable”, User.Name, false) in the required column.
Use the following display condition:
User.City==myCity

At the required position, read the value of the variable using GetVar(“userVariable”).

Erdal, what can I do to prevent the setvar and getvars from using up space on the report? I am using them to control whether or not to display a record and am using them in text fields in table lines. is there another way to use this feature? I made the font size 0 and color white so that they do not appear on the report, but they do use a line on the report so I have gaps in between rows that I want to print.

SetVar has an optional boolean parameter that can be used to suppress the output. Would that help?