Page 2 of 5

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Posted: Fri May 24, 2019 7:59 am
by HighAley
Hello.

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

Thank you.