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

Stimulsoft Reports.Net discussion
arysmyatov
Posts: 6
Joined: Mon May 14, 2018 9:35 am

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

Post by arysmyatov » Tue Mar 12, 2019 7:48 am

We are trying to transform data(decimal values, date, currency format) on the fly during the report generating from a template (ASP.NET core application).
It's needed to change the format of the date or amount depending on the user context (which is created by the request).
I know that this can be done(data transformation) with the help of custom functions. But it's using static methods to create the functions in which we cannot use the user context.
The question is: is there any way to use user context in the custom functions? Or is there some other mechanism for changing the settings of the date, currency formats etc. on the fly during the report generation?
HighAley
Posts: 8065
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 13, 2019 6:23 am

Hello.

The format of the dates and numbers depends on local settings.
If you need any other format you could change the Culture property of the report.
In this case, all currencies dates and numbers will be shown in the selected culture.

Also you could change the Text Format property of each text component separately or use the ToString() or other formatting methods.

Thank you.
arysmyatov
Posts: 6
Joined: Mon May 14, 2018 9:35 am

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

Post by arysmyatov » Wed Mar 13, 2019 8:04 am

Hi, thank you for your answer. But how could I change the Culture property of the report on the fly during the report generation process? And could I change direct the specific culture settings (e.g. currency or decimal format) by the report engine in the code?
HighAley
Posts: 8065
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 14, 2019 8:01 am

Hello.

You could change the Culture propety of the report with next code:

Code: Select all

report.Culture = "en-US";
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 » Fri Mar 15, 2019 9:03 am

@HighAley,

Let me please generalize the question. The example mentioned by @Arysmyatov is only one use case.
What we really need is to be able to get a tenant context in a multi tenant environment to be able to execute different functions based on this context.
Thanks
Vitaly
HighAley
Posts: 8065
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 Mar 16, 2019 3:49 pm

Hello,

What kind of functions do you want to execute?
There are different events of the report and each component of the report that you could use.
Maybe you could use other features of our product as Conditions or any other.
We need more information about your scenario.

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 Mar 18, 2019 8:23 am

HighAley wrote:
Sat Mar 16, 2019 3:49 pm
Hello,

What kind of functions do you want to execute?
Hi,
We are talking here about custom functions added using StiFunctions.AddFunction.

Thanks
Vitaly
HighAley
Posts: 8065
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 » Mon Mar 18, 2019 9:22 am

Hello, Vitaly.

Yes, you could use the AddFunction method to add custom functions.
Do you get any issue with it?

Code: Select all

StiFunctions.AddFunction("Category", "LookupCode", "LookupCode", "..", typeof(int), typeof(object), "...", new Type[] { typeof(object) }, new string[] { "a" }, new string[] { "b" });
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 Mar 18, 2019 12:08 pm

Hi,

I know we can and we are doing it. But as I mentioned before....
tayar wrote:
Fri Mar 15, 2019 9:03 am
@HighAley,
we need is to be able to get a tenant context in a multi tenant environment to be able to execute different functions based on this context.
So how can we do it within the code of this function?

Thanks
Vitaly
HighAley
Posts: 8065
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 » Tue Mar 19, 2019 11:39 am

Hello, Vitaly.

Our component is embedded in your web application.
You could get the HHTPContext in any available way.

Sorry, maybe we don't understand your question.
Could you elaborate on it?

Thank you.
Post Reply