Debugging BPM / Functions

Hi

In customizations you can choose Visual Studio to debug the customization code and step through the code lines. How can i do that with BPMs & Functions?

Thanks

Yeah, this is a fun one.

I’m not aware of a way to add breakpoints and step through BPMs/Functions (would love to know how to do this if it’s possible!)

A lot of people swear by the server logs but I found that fiddly and opted to write a function to handle my debug. Simplified, it looks something like this:

// Epicor Function - CommonFunctions.LogToFile
// ====================================================================================
// Request Parameters:
//   sFileLocation  System.String - network location of log file
//   sComment       System.String - text to add to file
//   bDateStamp     System.Bool - if true add line including current date and time
//   bSeperator     String.Bool - if true add a separator beneath comment line
// Response Parameters
//   nil
// ====================================================================================
// using System.IO;
// ====================================================================================

// add individual string to file
Action<string>WriteLine = (s) => 
{   
    StreamWriter obj = new StreamWriter(sFileLocation, File.Exists(sFileLocation));
    obj.WriteLine(s);
    obj.Close();
    obj = null;
};
// ====================================================================================
Action<string>WriteLog = (s) => 
{
    if (bDateStamp) {WriteLine("Log Entry: " + $"{DateTime.Now.ToLongTimeString()} {DateTime.Now.ToLongDateString()}");}
    WriteLine(s);
    if (bSeperator) {WriteLine("-------------------------------");}
};
// ====================================================================================

WriteLog(sComment); 

I’ve got a few common functions that I use universally. I added them all to a function library (in this example I’ll call it “CommonFunctions” and I include that library in other projects.

To call it from another function library:

if (bDebugMode){this.EfxLib.CommonFunctions.LogToFile(sDebugFile, "Whatever you want to see in your debug", bAddTime, bSep);}

Just remember your debug file is written from the server so you need a network path for the file, not a locally mapped drive letter.

I’m keen to see what others do, too. Debugging plays a big part of any dev’s repertoire and I’m always looking for a better way to handle this.

1 Like

I found some info online that might be of interest to you here
How to Debug a Epicor BPM in Visual Studio (youtube.com)

Little bit complicated, i haven’t achieved it yet as i cant see the remote machine in the debug dialog

  1. install remote debugger tool (on remote machine)
    Download Visual Studio Tools - Install Free for Windows, Mac, Linux
    (install on remote server if not already installed)

  2. access server path
    \[SERVER]\[ENVIRON]\Server\Assemblies\

  3. Create, save, edit & enable BPM

  4. Find the .cs file for your BPM
    \[SERVER]\[ENVIRON]\Server\BPM\Sources[DIRECTIVE TYPE BO-DT][METHOD][LATEST VERSION]
    eg \[SERVER]\d$\websites[ENVIRON]\Server\BPM\Sources\BO\Labour.GetList\8[BPM_Name].cs

  5. Open METHOD.cs file in Visual Studio

  6. Set Break Points in the .cs files

  7. Attach to wpw3.process
    Attach to process…
    Dialog to connect to debugging service
    find the server by name or public IP
    attach the process
    If multiple process, run cd C:\Windows\System32\inetsrv appcmd list wps on server to find the correct process ID
    then C:\Windows\System32\inetsrv appcmd list wps
    (select the one matching your current Epicor environment)

  8. Leave BPM open in Visual Studio

  9. Process BPM in Epicor

2 Likes

Had to use this process today. Same as you due to security restrictions I could not do remote debugging and ended up putting VS on the app server (this is development so ok). Ran into a few other particulairities, probably environemnt specific. I had to run VS as admin even though the account I was logged in with was a local admin. I also had to include the path of the app sever into the module paths so it would read any pdbs… as it said pdbs were missing when I went to put a breakpoint into the bpm code. Finally even though the breakpoint was indicating an error, I attached and executed the bpm and it started tracing. Hope that helps someone. Need more explicit screen shots then let me know.

Select Debug mode for Method/Data/Functions this will create files on the server that you can drag and drop into Visual Studio

There is a help article within the application on this - search for Debug Visual Studio

1 Like