Using user context data(from HttpContext) in the custom functions

Stimulsoft Reports.NET discussion
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,

let me try to explain step by step.
* We have a multi-tenant system.
* User USR1 executing an async task to generate a report for tenant ABC subsidiary EFG.
* The report contains a custom function.
* Within this function I have to know that the generation is executed for "tenant ABC - subsidiary EFG", find appropriate DB connection, set some security restrictions for that user and subsidiary and retrieve some information which needs to be returned by the function.

So my context is USER - TENANT - SUBSIDIARY which I don't see how I can get while using static function.

Hope it is clear now.

Thanks
Vitaly
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello, Vitaly.

If we understand you right you need to pass this information to the report.
You could do it using a report variable.
You can do it with the next code:

Code: Select all

report.Dictionary.Variables["Variable1"].Value = yourValue;
Thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,

that sounds good, but how do I get this instance of report property in the body of the static custom function?

Thanks
Vitaly
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello, Vitaly.

You could call the function by its name.
We don't see how you add and call the function.
If you open the Code of the report on the Code tab and get much useful information.

Thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,
Let us try to put all together, because I have a feeling we speek different languages.

1. There is a multi tenant system
2. Report is executed for one of the tenants
3. We are registering a custom function using

Code: Select all

StiFunctions.AddFunction("Category", "LookupCode", "LookupCode", "..", typeof(int), typeof(object), "...", new Type[] { typeof(object) }, new string[] { "a" }, new string[] { "b" });
4. The function is declared as static function in our code
5. In the report designer we have an expression which includes this function.
6. During report evaluation, backend function which is registered gets invoked
7. Report execution is an async background task, so HttpContext.Current is not available
8. Now in this function we need to know for which tenant the function has been executed (it can not be passed via the function parameters)

Hope now it is everything clear.

Thanks
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello.

In the ASP.NET a report is rendered by the .Net report engine.
The report is rendered on the server side.

It's not clear how do you run the report.

Our engine doesn't know where the report comes from.
All that you can do is to pass necessary information to the report right after loading it.
At this moment you should know the tenant and you could use this variable anywhere inside the report.

Sorry, I don't know how else we can we can help you to pass information to the function where it can't be passed.

Thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

HighAley wrote: Thu Apr 11, 2019 10:40 am All that you can do is to pass necessary information to the report right after loading it.
At this moment you should know the tenant and you could use this variable anywhere inside the report.
This is exactly my question. How can I pass it to the report so it will be available within a function
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello, Vitaly.

As we wrote to you before.
You could do it using a report variable.
You can do it with the next code:

Code: Select all

report.Dictionary.Variables["Variable1"].Value = yourValue;
Thank you.
tayar
Posts: 30
Joined: Tue Sep 26, 2017 9:22 am

Re: Using user context data(from HttpContext) in the custom functions

Post by tayar »

Hi,

Can you please provide a simple example how do I access the this Variable1 in the function which I register as

Code: Select all

StiFunctions.AddFunction("Category", "LookupCode", "LookupCode", "..", typeof(int), typeof(object), "...", new Type[] { typeof(object) }, new string[] { "a" }, new string[] { "b" });
This is the only missing piece

Thanks
Vitaly
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Using user context data(from HttpContext) in the custom functions

Post by HighAley »

Hello.

You could pass a value of the variable as a parameter of this function.

Thank you.
Post Reply