[IGN-7976]Get Name of Message Handler Programmatically

Is there any way to get the name/"message type" of the message handler from within its own script? I'd like to include the name in some custom logging and my aversion to having to manually edit the script constant to match the handler name is getting the better of me :sweat_smile:

No, this isn't directly possible. I wouldn't necessarily recommend going this route, but if you really wanted to, you can peek at the stack and find the 'filename' we feed into the Jython interpreter, which includes the handler name, which you could parse:

def handleMessage(payload):
	import sys
	filename = sys._getframe().f_code.co_filename
	# ex: <MessageHandlerScript:projectName/handlerName >	

I'll make a note to consider adding the handler name to this somehow. It'd be nice.

1 Like

Assign to __name__ before you compile and execute the function, perhaps?


We should really be doing that here and elsewhere, probably, yeah. Maybe I can roll this into the "make gateway event scripts proper extension functions" work I want to do in 8.3.

1 Like