Using message handler to run script

I have a frontend and backend gateway. Frontend contains perspective visuals and reporting modules. Backend contains the tag provider and DB connection. Frontend also has DB connection. Originally this was one gateway where all the scripting was on the one gateway. Now I have some tag event scripts which reside on the backend. I have a script based off of a tag event script which contains a call to save a report however it will not work because the frontend contains the report and the backend contains the tag calling the script. Whats the best way and example to complete this from the backend to the frontend? Can I use a message handler? If so can you give an example of what it would look like? I am very new to message handlers to do this type of thing.

Here is the existing tag event script being called from the backend tag:

This might help you Calling function on another gateway? - #3 by nminchin

Thanks! Here is my attempt of the tag event script.

Question I have is what to put for the hostName or remoteServers parameters. Would I be able to put the IP address of the gateway connection in one of these? Would I be able to put the gateway name of the frontend gateway which contains the messagehandler in one of these?

Having trouble determining which one to use and what to put for one of them. Thanks.

If I am reading things correctly, if the frontend gateway which contains the message handler I want to call has the system name of ‘Ignition-BladeSide-Frontend’ within the Gateway Settings, I should be able to include the line:

remoteServers = ‘Ignition-BladeSide-Frontend’

Is this correct?

1 Like

Yep, remoteServers should be the gateway system name, but it should be a list

Yea I did see it had to be a list. I am pretty sure I have everything correct but still not working.
Backend tag event script is creating the call of the messagehandler on the frontend.
Frontend project is called ‘PW_BladeSide’, frontend gateway is ‘Ignition-BladeSide-Frontend’.
When cycle_complete bit goes high it builds the call and then sends out the message.
Here is revised code for tag event script:

The gateway message handler on the frontend is:

It is supposed to call ReportControl script in the frontend gateway scripting and execute code that creates a folder if one is not already created, save the report as a pdf and save it in that folder, and also print the report out. It is not even creating the folder.
Here is the code within ReportControl. I know this part of the code works when I was able to do it without using a messagehandler:

def create_report_folders():
	"""Create report folders if they do not exist."""
	import os
	base_dir = 'C:\Reports'
	dirs = [base_dir]
	for furnace_number in ['548642', '548643', '548644', '548645', '548646', '548647']:
		dirs.append('{}\BT{}'.format(base_dir, furnace_number))
	for dir in dirs:
		if not os.path.isdir(dir):

def create_report(furnace_brass_tag_num, command='save'):
	"""Generate report for furnace.
		furnace_brass_tag_num (str): Brass tag number of furnace
		command (str): One of 'save' or 'print'
	furnace_cycle_id ='[BladesideSR]BS/FurnaceBT{}/Recipe/Lots/furnace_cycle_id'.format(furnace_brass_tag_num)).value
	params = {'FurnaceCycleID': furnace_cycle_id}
	if command == 'save':
		date =, 'yyyy-MM-dd HH-mm-ss')
		filename = 'BT{} {}.pdf'.format(furnace_brass_tag_num, date)		
		path = 'C:\Reports\BT{}'.format(furnace_brass_tag_num)		
		settings = {'path': path, 'fileName': filename, 'format': 'pdf'}'FurnaceCycle', parameters=params, action='save', actionSettings=settings)
	elif command == 'print':
		settings = {'primaryPrinterName': 'HP LaserJet M608 [847294]', 'backupPrinterName': 'none', 'copies': 1, 'printBothSides': True,
					'collate': True, 'useRaster': False, 'rasterDPI': 1200, 'useAutoLandscape': False, 'pageOrientation': 'portrait'}'FurnaceCycle', parameters=params, action='print', actionSettings=settings)

I am not getting to do anything yet so far…is there anything obvious I am doing wrong as to why its not working?

Also BrassTagNum is a string parameter within the UDT.

I would try putting some debugging messages into the message handler to see if it’s actually running at all. Add in some print statements or logger traces and check the gateway wrapper log or server logs.

I’m also not sure that '{BrassTagNum}' works. I thought in order to use that syntax you needed to use f'{BrassTagNum}', but I don’t think that’s available in Jython2.7. Try replacing with the '{}'.format(BrassTagNum) method.
Wait, why do you even need to indirectly reference it? Why not just
ReportControl.create_report(BrassTagNum, 'save')?

That was my next step, to see if its actually getting through. I know how to do the logger util statement inside a script function. Could I use the same thing? If I used the ‘print’ statement where would I look to see what it prints?


LOGGER = system.util.getLogger("Hello")

LOGGER.trace('I tawt I saw a puddy tat..')

prints in a gateway context print to the wrapper log

It all worked when everything was on one gateway with the following code for the tag event script on cycle_complete tag

I think the squiggly brackets mean you want to use the value of BrassTagNum and not the actual string. I thought I can just use this same code but complete lines 5 and 6 in the message handler on the frontend since the frontend contains the report I want to use and also where I want to save the file to.

Pretty sure that syntax is only supported in Python 3+ (and it needs the f notation at the start)