Mobile apps: How to use OnDestroy to avoid Invalid call of the * error?

Mobile apps: How to use OnDestroy to avoid Invalid call of the * error?

  

Hello everybody, any idea how to correctly use the OnDestroy to avoid these kind of problems?


"Invalid call of the 'BottomBarNewNotificationReceived' client action of the 'MainFlow.Notifications' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action."


I do not use a platform's client action being used as an event handler nor a setTimeout function. I have this from time to time, no idea how to consistently reproduce.


I see there are lots of similar posts, but no clear solution:


https://www.outsystems.com/forums/discussion/27184/how-to-remove-an-event-handler-in-ondestroy-action/

https://www.outsystems.com/forums/discussion/33965/invalid-call-of-the-login-client-action/

https://www.outsystems.com/forums/discussion/30186/invalid-call-of-the-client-action-of-the-since-the-latter-is-not-current/

https://www.outsystems.com/forums/discussion/26797/invalid-call-of-triggerexit-client-action/

https://www.outsystems.com/forums/discussion/21187/invalid-call-of-the-onnotificationreceived-client-action/

https://www.outsystems.com/forums/discussion/32696/error-message/

https://www.outsystems.com/forums/discussion/28519/removing-pushwoosh-notificationreceived-event-listener-ondestroy/

https://www.outsystems.com/forums/discussion/27212/mobile-app-login-invalid-call-of-the-login-client-action-of-the-common-login/

https://www.outsystems.com/forums/discussion/26536/invalid-call-of-the-checkandchangeanchors-client-action/

https://www.outsystems.com/forums/discussion/21671/mobile-app-error-invalid-call-of-the-triggeronupgradeprogress/

https://success.outsystems.com/Documentation/10/Developing_an_Application/Implement_Application_Logic/Screen_and_Block_Lifecycle_Events#On_Navigating_Between_Screens


Thanks for your input!


Kind regards,


Adrian


Hi Adrian,

Is BottomBarNewNotificationReceived an action from a plugin you're using or something that you control?

Yes, I do. But I had these kind of messages in other screens; I begin to think that you can potentially have this on any screen where you use a listener (either on an event or OnAfterFetch listeners) and is caused by some time sensitive issue...


You have to use the OnDestroy event of the BottomBar block to remove the NotificationCounter... action from its subscription source.

You probably have a javascript node where where you're attaching that action to an event, right?

João Neves wrote:

You have to use the OnDestroy event of the BottomBar block to remove the NotificationCounter... action from its subscription source.

You probably have a javascript node where where you're attaching that action to an event, right?

"You probably have a javascript node where where you're attaching that action to an event" - no, I do not use javascript; I only set the listener to the event (see screenshot above). Same thing when you have a screen with an aggregate or Data Action and set the OnAfterFetch listener (local method) on it- how do you remove it? 


Can you share the oml or at least that block?

João Neves wrote:

Can you share the oml or at least that block?

Here it is, only the core module; it won't compile but you will get the idea... Thanks for your help!


Solution


The SyncLocalAlerts action is an asynchronous that can take long time to complete (since it goes to the server). While the function is executing, the user might navigate away to another screen. When the action finishes it will trigger the Notifications Update event which will be handled by an handler of a screen/block that was already destroyed, hence the error.


You should prevent that error, checking a control variable (eg: IsDestroyed) which should be set when the block is destroyed. If the block is destroyed, you skip the event trigger.


Solution

Yes, makes sense; thanks!

João Neves wrote:


The SyncLocalAlerts action is an asynchronous that can take long time to complete (since it goes to the server). While the function is executing, the user might navigate away to another screen. When the action finishes it will trigger the Notifications Update event which will be handled by an handler of a screen/block that was already destroyed, hence the error.


You should prevent that error, checking a control variable (eg: IsDestroyed) which should be set when the block is destroyed. If the block is destroyed, you skip the event trigger.



Hi Joao, please, can you be more specific with an example using this variable IsDestroyed?

Hi Jorge,

1) Create a local variable IsDestroyed in the block

2) Use the OnDestroy event handler of the block to set the IsDestroyed = true

3) Place an If after the call to SyncLocalAlerts to check if the IsDestroyed = true ... and if yes ... go to End - because the block has already been destroyed.

Hi Joao, thank you for your answer. But what happens if i called an OnAfterFetch event and then the screen is destroyed, how can i stop that onAfterFecth before going to the other screen?

Jorge Trujillo wrote:

Hi Joao, thank you for your answer. But what happens if i called an OnAfterFetch event and then the screen is destroyed, how can i stop that onAfterFecth before going to the other screen?

OnAfterFetch won't be called if you navigate away

Actually is being called. Take a look of the following error when I had navigated from the screen with the OnAfterFetch to a new one:

 Invalid call of the 'GetLocalTeamMembersLotsByUserIdOnAfterFetch' client action of the 'ScreenDesignImplementation.LotTasksList' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action.

Are you sure that is is not being called in other places other than the Aggregate OnAfterFetch?

Yes, Im sure.

Which Platform Server version are you running?

Platform Server 10.0.900.0

The OnAfterFetch is actually called, depending on the Platform version. I reported this bug to Support in June this year, and they verified it's a bug, and the fix would be coming end of July. So it should be fixed in the most recent Platform versions, though I haven't checked the release notes. Given that 10.0.900.0 is the latest version, apparently it's not.

The issue was fixed on 10.0.900.0:

RPD-3216 - https://success.outsystems.com/Support/Release_Notes/10/Platform_Server/Platform_Server_10.0.900.0

You have to republish your applications in order to have the issue fixed.


Cool, thanks for the info.

João Neves wrote:

The issue was fixed on 10.0.900.0:

RPD-3216 - https://success.outsystems.com/Support/Release_Notes/10/Platform_Server/Platform_Server_10.0.900.0

You have to republish your applications in order to have the issue fixed.



Hi Joao, I did it, and still I'm getting the same error.

Hi Jorge, can you share an example of the problem happening?


Like João Neves said the issue you are having should be fixed in version 10.0.900.0.


Also, consider reporting this to OutSystems support.

Diogo Paulo wrote:

Hi Jorge, can you share an example of the problem happening?


Like João Neves said the issue you are having should be fixed in version 10.0.900.0.


Also, consider reporting this to OutSystems support.

Hi Diogo, I already reported the issue to OutSystems, they are still working on that. thanks


Hello,

Is there an update on this matter? I face the same issue. 

I also applied the control variable like suggested by João Neves, but it the error is still triggered.


Thank you


Maria João Portela wrote:

Hello,

Is there an update on this matter? I face the same issue. 

I also applied the control variable like suggested by João Neves, but it the error is still triggered.


Thank you

Hi, Maria.

Can you please share an example eSpace/block where this issue is reproducible? Please also confirm you are using OutSystems Platform version 10.0.900.0 or above.

Thank you.


Hello Rui,

I can confirm that the version is superior (10.0.907.0) but I can't share the espace.

I can share screenshots:

This is where the errors are popping up. The two OnAfterFetch keep throwing this error:

Invalid call of the 'GetLocalUserAndLocalSettingsOnAfterFetch' client action of the 'HomeScreen.HomeScreen' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action.

Invalid call of the 'GetLocalAppIntegrationActiveLinksOnAfterFetch' client action of the 'HomeScreen.HomeScreen' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action.

Do you see anything wrong here?

Thank you




Hello!

Any news on this matter?


Thank you!