Get appserver name from within BPM

Our environment is set up so that test environments (we have many) are refreshed from a backup of production. The entire process is managed by a script.
We also have some method directives and data directives that send emails our under certain circumstances.
It is not always clear which environment the email is coming from. I would like to include the appserver name or database name in the email so that it’s clear which environment the email is coming from.

I’ve seen a few similar posts but nothing that seems to directly answer the question.
The callContextClient does not seem to have this information.

Any insight into how I can retrieve the appserver name or database name from within a directive?

There’s a couple different ways you can do it. Two that I know of are using Db.ConnectionString.Contains(“”) , or use the newish BPM condition.

To use the BPM condition widget, you have to set an appserver as production in the epicor admin console. I’ve noticed for my Test restore process this flag gets set every time I restore Test from Production, so you could probably add something to your script to handle this.

You could just add Db.ConnectionString as a string variable and add that to your email template too.

I wish they had designated this in the web.config not the DB; shortsighted. You can do it yourself if you like.

Add to web.config inside the appSettings node

    <add key="IsProduction" value="true" />

To then use it in BPM land use the following to get the key value.

var x =  System.Configuration.ConfigurationSettings.AppSettings["IsProduction"];

Sorry a bit late to the party … but to get the appserver you could use the ‘AppServerURL’ property of the Session variable as shown in the code snippet below -

    string[] server = Session.AppServerURL.Split('/');
    switch (server[3].ToUpper())
        case "PRODUCTION":
            Database = string.Empty;
        case "TRAINING":
            Database = "Train";
        case "TEST":
            Database = "Test";
        case "PILOT":
            Database = "Pilot";
            Database = string.Empty;

Never ever use ConfigurationSettings in your BPM/EFx custom code. You will have a lot of troubles during upgrade to the future versions of the product since this type is not a part of .NET Core/.NET 5/.NET 6/…

BPM/EFx provides a condition checking Production vs Non-Production environment.

That is what we use…

@GaryWarn Thanks for the code, it works just fine.