COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Report Studio => Topic started by: irvingbos on 17 Nov 2015 02:28:28 PM

Title: trapping the exit of a prompt screen
Post by: irvingbos on 17 Nov 2015 02:28:28 PM
Hi, I am interested if anyone knows of a technique to trap the exit event (closing the window) of a Cognos prompt screen. I am guessing it will involve Javascript / JQuery, which is fine, but not sure from there..  any suggestions are welcomed!
Title: Re: trapping the exit of a prompt screen
Post by: bdbits on 18 Nov 2015 02:11:47 PM
What are you actually trying to accomplish? If you want to add custom validation, the prompt API (javascript) has hooks for that without trying to trap events.

My concern with hooking into an event is that it might change in your next version upgrade. Cognos says they will maintain prompt API compatability in future releases.
Title: Re: trapping the exit of a prompt screen
Post by: irvingbos on 18 Nov 2015 02:46:45 PM
Hi, we have a prompt screen where users can select customers (possibly 100s). It also has the ability to write some simple data (esentailly lists of thier selections, so they re-use them in the future) back to the databse (via SPs). These lists first get stored as cookies, then when the 'submit' happens the data is written to database. I want to warn the user in the scenario that they have saved a list to a cookie, but is now bailing out of the prompt screen, so the write back to the datbase never happens. The warning would be something to the effect that they might lose that list if their cookies get cleared.
Does that help?
Title: Re: trapping the exit of a prompt screen
Post by: bdbits on 23 Nov 2015 10:50:17 AM
Yes; that must be a lot of javascript you got going on there. :)

I think you want to add a listener to the window beforeunload event, which unlike unload can be cancelled. I have sometimes noticed Cognos code will override event handlers, which can be a royal pain in the behind to overcome. But that is what I would try first.
Title: Re: trapping the exit of a prompt screen
Post by: irvingbos on 23 Nov 2015 01:52:06 PM
thanks bdbits, will try that; I was realized after i posted that it is not just close window i would need to trap, but also the back button in the browser, and possibly more spots.. Essentially, when-ever the report closes, through any means.  this could get interesting..
Title: Re: trapping the exit of a prompt screen
Post by: bdbits on 25 Nov 2015 09:11:31 AM
Sometimes what seem like different actions will trigger the same events, so you may find beforeunload gets triggered with a back button, etc. I don't have a reference for what action triggers what events, but if you get it working for one you can then try the others and see if it triggers the same event. I would start with just an alert() for testing purposes. You should be able to create one function to hook to however many events you need.