This post is directed towards people, like myself, who have struggled trying to gain a clear understanding of how to reference a session within an Epicor form module customization in order to isolate the Epicor application server/host name.
Most of you already know how to do this, but some of us may find this information useful.
For my particular requirement, I wanted to write a log file back to the Epicor server whenever someone clicked on a certain checkbox on the Sales Order Entry form. Therefore, the customization was applied to:
I started by instantiating a session reference within the top-level public class of the form module:
Note here that I have also reserved a string variable ("
strEpiServer") that I will use later to parse the server host name (you’ll see why as you read further).
_currSession reference instantiated, I now need to define it within the context of the form upon which I’m applying the customization. In my case, I did this task within the
BeforeFieldChange form event, but the decision concerning when you might do this will depend on your specific needs:
_currSession = (Ice.Core.Session)oTrans.Session;
Perfect. Now I have the current session referenced within the object namespace.
The Epicor application server session variable can now be “pulled” from the namespace in this fashion (other session variables can be referenced from this point, as well) :
… however, this value is returned as a fully qualified “Net.TCP” value:
Here, the Epicor server name (“host name”) needs to be parsed out of that string.
To do this, I created a small method that specifically targets the Epicor server name within an array and returns it back to the calling process:
To call into this method, I simply used the previously reserved string object to hold the return value from the method; passing along the
AppServer object from the previously acquired session namespace :
strEpiServer = GetAppServer(_currSession.AppServer);
Now, I can use Epicor server string value to reference a path in which to write a log file:
string strPath = @"\" + strEpiServer + @"\EpicorData\CustomCodeLogging" + strLogFileName;
Remember - this example applies to client-side session referencing from an Epicor form module customization. It does not apply to BPMs.