Monday, November 6, 2017

Determine if code is running in Batch

Recently I was tasked with fixing an issue where our Project invoice proposals were not posting while in batch. 
I discovered that 'WinAPI' was being called in some custom code and was able to fix it.
However, I also realized that the custom code that was being used need to be called in Batch ONLY.  Due to some issues with Citrix and the AX Client, I had to prevent the AX Client from running this code.

This proved to be difficult as I was about 4 classes deep into Proposal posting and the isRunningBatch() method isn't available. (Or at least I couldn't find a way to get back to the 'RunBaseBatch' class).

So, I found a quick little solution that appears to be working:

xSession xSession = new xSession();
xSession.AOSName();

Whereas our batch server is never used for the client, I can just check the the AOSName against my batch server name and run code if they match.

Probably not the best solution, but it seems to work.