Equipment Scheduler event popup trigger

Hi,
image
I have created a popup in equipment scheduler, in which on click on the popup , the event should be deleted. However, this logic is working even when not clicked on the popup. Please refer the attached picture for reference,

Thanks in advance

Please don’t post snap shots of code, instead copy and paste the code and then use the preformatted text option </>. This will make it so that the code retains its formatting and other users can easily copy your code to test or modify.

I assume that what you are really want to happen is that when the menu button is click to run the named query, and then display the message box.

You have a few problems:

  1. The system.gui.createPopupMenu() takes two lists as parameters, you have provided a single dictionary
  2. The script you want to execute should be within the function that you have assigned to that menu item.
def deleteSchedule(event,machID = eventId):
    dlparams = {'iMachineID':machID}
    system.db.runNamedQuery('Scheduler/deleteSchedule',dlparams)
    system.guil.messageBox('You deleted event for {}'.format(machID))

names = ['Delete']
functions = [deleteSchedule]
menu = system.gui.createPopupMenu(names,functions)
menu.show(event)

You can see more examples on how to use the Popup menu in the manual.
https://docs.inductiveautomation.com/display/DOC81/system.gui.createPopupMenu

Also, generally having any type of “delay” on the GUI is not recommended, even though you have done it in a thread safe way, I’m not sure what the purpose of waiting 2.5 seconds to refresh is.

You are stopping your timer right after you start it, so it will never execute your function. You can’t call an component methods from another thread anyways (lockup risk), so it is probably just as well that it didn’t work. Use the delay argument to system.util.invokeLater instead.

{ Don’t use timers or threads or any sleep calls from jython’s standard library. Use Ignition’s script functions and/or native java classes. }