Page 4 of 5
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Mon Jun 17, 2019 11:44 am
				by tayar
				Hi,
HighAley wrote: ↑Mon Jun 17, 2019 11:40 am
You could create the variable with your code and it will not be visible to the users.
 
I think this what I am missing. Can you please provide an example of this?
Thanks
 
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Mon Jun 17, 2019 8:28 pm
				by HighAley
				Hello.
Our product is very complicated. One class could have many constructors.
As it it with the StiVariable class.
			
		
				
			
 
						- VariableConstructors.png (29.74 KiB) Viewed 5597 times
 
		
		
		
			 
You could use any of them.
Usually we suggest to create a variable that you need in the Designer and look at the code tab.
You will find necessary code there. Just add a necessary variable to the Dictionary.
Thank you.
 
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Tue Jun 18, 2019 4:03 pm
				by tayar
				HI,
Thanks. This is valuable. And now last thing. How do I get the value of this variable within a function which is registered using 
Can you please give me an example?
Thanks
  Vitaly
 
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Tue Jun 18, 2019 7:27 pm
				by HighAley
				Hello.
You could call the variable from anywhere inside the report by its name.
We can't give you more detailed information because we don't see your function and the variable.
Thank you.
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Wed Jun 19, 2019 7:12 am
				by tayar
				Hi,
But, as explained, I can not use this variable in the report. I need it in a function.
Let's say I register a variable StiVariable("MyCustomVariable", "MyValue")
Can you please provide an example of a function which simply returns the value of this variable.
Thanks
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Tue Jul 02, 2019 3:29 pm
				by tayar
				Hi,
Would it be possible to get an example of a function as described in a message above?
Thanks
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Tue Jul 02, 2019 5:39 pm
				by HighAley
				Hello.
Here is the custom function that returns the variable MyCustomVariable.
			
		
				
			
 
						- CustomFunction.png (13.01 KiB) Viewed 5522 times
 
		
		
		
			 
Please, look at the attached report template.
Thank you.
 
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Mon Jul 15, 2019 1:31 pm
				by bra
				HighAley, I have copied your code in Visual Studio and it cannot find InitializeComponent method. Am I missing some using statement with reference to some namespace of extension methods?
Or you meant we need to derive StiReport class in every single report as a script?
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Mon Jul 15, 2019 8:47 pm
				by Lech Kulikowski
				Hello,
Could you explain your issue in more details?
Thank you.
			 
			
					
				Re: Using user context data(from HttpContext) in the custom functions
				Posted: Tue Jul 16, 2019 12:35 pm
				by bra
				I need to implement function that must be available from a report and is able to receive a string parameter. Inside it I must have access to current report's object instance variables, get a variable of dictionary type use provided string parameter as an index of value in the dictionary and return the value.
Code: Select all
const string DIC_VAR_NAME = "custom_dictionary";
public string GetDictionaryValue(string key)
{
   // get current report instance
   var currentReportObject = ??? (don't know how to get the object, must be of type StiReport or probably it's descendant)
   // get dictionary from report
   if (!dictionaryObject.IsVariableExist(DIC_VAR_NAME)) return "";
   var dictionaryObject = currentReportObject.Variables[DIC_VAR_NAME];
   var dictionary = dictionaryObject as IDictionary<string, string>();
   if (dictionary == null) return "";
   return dictionary[key];
}
As you can see I cannot use static function because I need instance members (need to get current StiReport instance somehow).
So two questions:
1) how to register such a function in Report from code?
2) how to get current report object instance to be able to operate with variables that were assigned from code?