Perspective Button - Script event only works in designer

Ignition Version: 8.1.23

I have a numeric entry field and a "submit" button that when I click the button I have my script write the data to mysql database. It works when running it in the Designer but when I test on the web or an iPad it doesn't write the data.

Below is the script. I have a second event to change the navigation and that works without any issue on the web/iPad.

def runAction(self, event):
	var_wb_temp_in = self.getSibling('text-hx_wb_temp_in').props.value
	
	system.db.runNamedQuery('insert_mr3_dailylog', {'wb_temp_in':var_wb_temp_in})
	

Not sure why this is working in the designer and not in testing.

Do you mean in the designer's script console? Or Perspective preview?

Preview mode when looking at the view

Hmm. Non-obvious. Is anything showing in the gateway log? Like auth requirements that might apply to that named query?

Only thing i see is:

Received event for missing view "MR3 Daily Log@C"

Sometimes when we see this, the View is failing to receive updated content from Save events. Could you try saving your project again, then opening the "test" page again, and see if it begins working?

I saved and updated the project and then re-opened the page via "Launching Session" from the designer and it still results in the same behavior and log in gateway.

Curious. The next step would be to place logging into that script to see exactly what is occurring. Create a new logger, log some sort of useful info between each line, save the project, then try clicking the button in your View again.

def runAction(self, event):
    # copying this from the forums might result in formatting issues (spaces vs tabs) so verify script has no errors before saving.
    myLogger = system.util.getLogger("IA_DEMO")
    myLogger.info("Beginning")
    var_wb_temp_in = self.getSibling('text-hx_wb_temp_in').props.value
    myLogger.info("Middle")
	system.db.runNamedQuery('insert_mr3_dailylog', {'wb_temp_in':var_wb_temp_in})
    myLogger.info("End")

I put that script in the event and i don't see anything different in the log. Its almost like its not even running the script at all. I double checked to make sure the project was saved and updated. I also double checked to make sure it was enabled :slight_smile:

If you're not seeing the logging, either your session is broken or your Designer is not saving changes. I recommend closing your designer and any open Perspective pages in your browser. Wait for any inactive sessions to be removed from the session registry (on the Gateway you can look under Status > Perspective Sessions and wait for any sessions with your IP to be removed).

Now open a session to your test page and try again. If at this point you still do not see the logging, then I recommend you contact our Support team.

1 Like

I have a second event to change the navigation and that works without any issue on the web/iPad.

Might be talking nonsense here but how is your button events set up ? All in one script or all different events?. I have had it in the past where if I chose separate events they do not follow any kind of order, i.e your navigation is happening before the query, since then I script everything.

Try disabling the navigation and test only the named query.

1 Like

This was it! I had a second action on my onClick Event, 1. Script and 2. Navigation and i was under the impression it was doing it in that order. It now writes the data to the database and i will just have to figure out how to change the navigation.

More interesting, its surprising it has up arrows and down arrows for the actions to organize them but it doesn't follow the order.

1 Like

Glad you figured it out, been there myself scratching my head. I guess it worked in the designer as the designer doesn't navigate, so was allowed to do the query.

https://docs.inductiveautomation.com/display/DOC81/system.perspective.navigate

Thank you! Appreciate all the responses.

Multiple Actions on one event is asking for trouble. They run asynchronously, so there's no guarantee one will complete before any other. This does also explain why it's working in the Designer -- the Designer ignores all navigation attempts, so only the Script action was doing anything.

I recommend you place your navigation into the same script as your query, and perform the navigation AFTER the query.

Yup, works like a charm now. Thank you!

1 Like