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 » Tue Mar 19, 2019 12:43 pm

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: 8010
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 » Wed Mar 20, 2019 12:10 pm

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 » Wed Mar 20, 2019 4:14 pm

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: 8010
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 » Thu Mar 21, 2019 9:29 am

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 » Mon Apr 08, 2019 4:01 pm

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: 8010
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 » Thu Apr 11, 2019 10:40 am

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 » Wed May 08, 2019 2:47 pm

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: 8010
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 » Sat May 11, 2019 11:39 am

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 » Tue May 21, 2019 3:29 pm

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: 8010
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 » Fri May 24, 2019 7:59 am

Hello.

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

Thank you.
Post Reply