Referencing the Epicor Server Host Name (Session Variable) within a Form Customization

customization

(Bill Anthony) #1

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:

App.SalesOrderEntry.SalesOrderForm

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).

With the _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) :

_currSession.AppServer

… however, this value is returned as a fully qualified “Net.TCP” value:

net.tcp://ERPSERVERNAME/EpicorApplicationInstance

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.


(Haso Keric) #2

You could use the Uri Helper:

1st Option - Quick Extract of Host

string sHost = (new Uri("net.tcp://ERPSERVERNAME/EpicorApplicationInstance")).Host; // Output: ERPSERVERNAME
string sHost = (new Uri( ((Ice.Core.Session)oTrans.Session).AppServer) )).Host; // Output: ERPSERVERNAME

2nd Option - Create Object

var url = new Uri("net.tcp://ERPSERVERNAME/EpicorApplicationInstance");

url.Host // ERPSERVERNAME
url.AbsoluteUri // EpicorApplicationInstance
url.Port // 808
url.Scheme // net.tcp

Easy Path Concat

string sLogFile = System.IO.Path.Combine(@"\\"+ sHost, "EpicorData", "CustomLog.log");

More info for anyone who hasn’t used it yet

System.IO.Path.Combine(@"C:\abc", "MyFileName.xml") // C:\abc\MyFileName.xml
System.IO.Path.Combine(@"C:\abc\", "MyFileName.xml") // C:\abc\MyFileName.xml
System.IO.Path.Combine(@"\\SERVERPATH", "MyFileName.xml") // \\SERVERPATH\MyFileName.xml
System.IO.Path.Combine(@"\\SERVERPATH\", "MyFileName.xml") // \\SERVERPATH\MyFileName.xml

(Bill Anthony) #3

Thanks, @hasokeric.

I’ll certainly want to try your example the next time I need to parse out the Epicor server host name.

I appreciate your follow-up!