Question

Get current session variables in dashboard

  • 27 January 2023
  • 6 replies
  • 156 views

Userlevel 1

For rather complex reasons, I want to get the current environment name in a customised dashboard. The closest I can find in Object Explorer is MainController.Session.AppServer, which I can extract the environment name from as it is part of the AppServer string, but this is not recognised when I run the code checker, and nor is any other member of MainController.Session. Can anyone point me in the right direction?

ERP 10.2.700

Kind regards,

Peter


6 replies

Userlevel 3

Don’t forget to convert Session to Ice.Core.Session.  In Object Explorer, you’ll see it (usually) comes back as an Object.  

ex: var session = (Ice.Core.Session)oTrans.Session;

 

Let me know if that’s not the issue you’re running in to.

Userlevel 1

Hi Fred,

Thanks for the reply. Ice.Core.Session won’t compile. I get “Error: CS0234 - line 260 (519) - The type or namespace name 'Core' does not exist in the namespace 'Ice' (are you missing an assembly reference?)”

I know Ice.Core.Session works in customisations of standard screens because it is used in our Part Maintenance customisation, but it doesn’t seem to work in customisations of dashboards.

Kind regards,

Peter

 

Userlevel 3

I’m going off the top of my head since I haven’t done dashboards in a while.  You may have to add a referenced to Ice.Core.dll so that you get the namespace.  

Userlevel 1

Thanks Fred, I will take a look on Monday. I’m off home now, have a nice weekend!

Kind regards,

Peter

Userlevel 1

Sorry Fred, I’m really struggling with this. I tried var assembly = Assembly.LoadFile(“Ice.Core.Session.dll”) but the compile failed with “The name 'Assembly' does not exist in the current context”. Am I missing a using reference?

Userlevel 1

OK, I’m a little further forward with this - I added using System.Reflections to my code, which solved the previous error, but now I have come up against something of a catch 22 situation - if I try to get the file by referencing just its name, Ice.Core.Session.dll, I get an error saying I need to specify the full path. No problem, I know the full path, it is C:\Epicor\ERP10Client\EpicorERPPilot\Client\Ice.Core.Session.dll. But this obviously includes the environment name.

So in order for the code to get the name of the environment it is running in… it needs to know the name of the environment it is running in!

 

Reply