Utilizing Session in a BPM when BPM is fired from a rest call

Hello!

I’m utilizing the following code in a BPM, works flawlessly.

string prefix = "ERP";
char[] delimeter = { '/' };
string[] sections = Session.AppServerURL.ToString().Split(delimeter);
string extendedEnvironment = sections[3];

parsedEnvironment = extendedEnvironment.Substring(extendedEnvironment.IndexOf(prefix) + prefix.Length).ToUpper();

bool isLive = string.IsNullOrEmpty(parsedEnvironment);
      
if(isLive)
{
  parsedEnvironment = "LIVE";
}

The problem is, when I call my BPM from a REST call (the rest call simply changes a checkbox), I get the following error:
Server Side Error
Server Side Exception
EpicorServerException
Description: BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.
Program: UD02.Update.dll
Method: A001_CustomCodeAction

I’ve isolated it to this specific code, which of course is one of the most critical components of the BPM.

How can I properly utilize a BPM session when said BPM is fired from a REST call?

Sooo I found here on the form that session info is only obtainable via the rich client. That makes sense.

I went a hacky way and obtained the current IIS app pool name instead, since app pool names match session URL names.

2 Likes