Can't reopen the popup after clicking the OK button to close it

I created a popup that appears when I click the event button. For some reason, after I click the OK button in the popup to close it, I can't reopen it. I’ve created other popup buttons using the same script, and they work fine—only this one doesn't reopen.

This is the script for Event button.


def runAction(self, event):

	import system
	from java.text import SimpleDateFormat
	
	# Logger setup
	logger = system.util.getLogger("EventPopupButton")
	
	try:
	    # Get parameters
	    catid = self.parent.parent.parent.getChild("FlexContainer")\
	        .getChild("TabContainer")\
	        .getChild("EventInfoEmbeddedView").props.params.CatID
	
	    descid = self.view.params.DescID
	    date_raw = self.view.params.Date
	    time_raw = self.view.params.Time
	
	    date_str = str(date_raw)
	    time_str = str(time_raw)
	    datetime_str = date_str + " " + time_str
	
	    logger.infof("catid=%s, descid=%s, date_str=%s, time_str=%s", catid, descid, date_str, time_str)
	
	    # Convert to ISO format
	    input_format = SimpleDateFormat("yyyy-MM-dd h:mm a")
	    output_format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
	
	    try:
	    	date_obj = input_format.parse(datetime_str)
	        iso_date = output_format.format(date_obj)
	        logger.infof("ISO datetime = %s", iso_date)
	    except Exception as dt_err:
	        logger.error("Date/time parse failed: {} - datetime_str = '{}'".format(str(dt_err), datetime_str))
	        iso_date = ""  # fallback to blank or default

	    # Close popup if already open
	    try:
	        system.perspective.closePopup("EventDescPopupID")
	    except:
	        logger.warn("Popup wasn't open or failed to close. Continuing...")
	
	    # Open popup with parameters
	    system.perspective.openPopup(
	        id="EventDescPopupID",
	        view="Templates/Popups/Event Description",
	        params={
	            'Date': date_str,
	            'Time': time_str,
	            'CatID': catid,
	            'DescID': descid,
		            'ISO_DateTime': iso_date
        },
	        title="Event Description",
	        modal=False,
	        draggable=True,
	        showCloseIcon=True,
	        position={"left": 300, "top": 150}
	    )
		
	    logger.info("Popup opened successfully.")
	
	    # Send session-scoped message
	    system.perspective.sendMessage("CatEventDescPopup", payload={
	        "CatID": catid,
	        "DescID": descid,
	        "Date": date_str,
	        "Time": time_str
	    }, scope="session")
	
	    logger.info("Message sent to CatEventDescPopup.")
	
	except Exception as e:
	    import traceback
	    logger.error("Popup failed:\n" + traceback.format_exc())

This one is for ok button.


def runAction(self, event):

	from java.text import SimpleDateFormat
	from java.util import Date
	
	
	# Get the current date and time
	now = Date()
	
	# Define the ISO 8601 format
	iso_format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
	
	# Convert the date to ISO 8601 format
	iso_date = iso_format.format(now)
	
	logger = system.util.getLogger("EventInfoEdit")
	catid = self.parent.parent.parent.getChild("FlexContainer_0").getChild("FlexContainer").getChild("CategoryContainer").getChild("Dropdown").props.value
	descid = self.parent.parent.parent.getChild("FlexContainer_0").getChild("FlexContainer").getChild("DESCContainer").getChild("Dropdown").props.value
	date = self.parent.parent.parent.getChild("FlexContainer_0").getChild("FlexContainer").getChild("DateTimeContainer").getChild("DateInput").props.value
	iso_datetime = date

	datetime = iso_format.format(date)
	logger.infof("DateTime: %s", datetime)
	system.perspective.sendMessage("RefreshEventInfo", payload= {"CatID": catid, "DescID": descid, "Date": date, "DateTime":datetime}, scope = "session")
	
	system.perspective.closePopup("EventDescPopupID")

Are there any errors, in your gateway or browser console logs?

As a secondary point; don't trust LLMs (I'm assuming) to give you useful help with Ignition.
This entire block:

Is exactly equivalent to these two built in system functions: iso_date = system.date.format(system.date.now(), "yyyy-MM-dd'T'HH:mm:ss")

Similar advice applies to your first code snippet. Until/unless you know better, if you're reaching to an import from Python or Java, you're doing it wrong.

3 Likes

Thank you for the reply! I'm pretty new to Ignition. I do see an error in the browser console logs, but I don't think it's something that would affect what I'm working on right now.

Post stack traces as pre-formatted text, not images, see Wiki - how to post code on this forum. Just copy the stack trace as a whole and put it in the pre-formatted text block.

Neither of the scripts you gave us have 265 lines present, so its likely the source is elsewhere (maybe your message handler?). Looking at the error, it appears you forgot to close a pair of parentheses somewhere.

Additionally, you should NOT be importing anything within a function definition. You should never have to import system, its always available in all scripting contexts.

Also, the logger methods also accept a trace object as an additional argument. Don't stringify the traceback you get from your exception clauses. Example:

except Exception as dt_err:
	        logger.error("Date/time parse failed: {} - datetime_str = '{}'".format(str(dt_err), datetime_str))

Should be

except Exception as dt_err:
	        logger.errorf("Date/time parse failed for datetime_str '%s'", datetime_str, dt_err)
2 Likes

An additional housekeeping nitpick:

The values for all these dropdown components should be bidirectionally bound to custom properties on the view or the view root container.

It makes it extremelty robust and makes access much simpler. Your access to the item is now catId = self.view.custom.catId, and will work no matter where the button is in the view container hierarchy.

2 Likes