145
Views
7
Comments
Solved
On Initialize is triggered. DOM related

Hey all!


I'm sorry. maybe this is actually super simple, but I've checked the documentation and I have some doubts. 

"On Initialize is triggered. Since the DOM of the default screen is not completely loaded when this event occurs, you can use this event handler to implement all the logic that doesn’t require the DOM, such as to initialize some default data. "


Can you give me more specific (practical) examples of what can be used then?

Maybe even for the rest of the Lifecycle Stages.. 



P.S. I know it might sound repetitive, but I have checked the post that was marked as the solution and also this page (https://success.outsystems.com/documentation/11/developing_an_application/implement_application_logic/screen_and_block_lifecycle_events/#on-initialize), etc. I find it to be a complex topic with the potentialities and DOM relationship, etc. It's challenging when someone is not as familiar with coding



Can someone help?

Thank you in advance! 


2023-08-28 07-00-10
Paulo Torres
Champion
Solution

OnInit is very useful if you want to assign values into a variables for example, create lists etc... Everything in client side you have to prepare before to go to the server (Queries, API's) and also values you need on the screen.

Example: If you want to set a default value in local parameter of your screen but you have logic to decide which value you will set.

Another example:

2023-10-27 13-43-55
Mafalda Melo Oliveira

Hello @Paulo Torres 


Firstly, thank you for providing the examples!

Could you also provide some examples of actions and tasks that can and should be done for the other events? It would be greatly appreciated.


I have another question:

"Even before the data from the aggregates and the data actions is fetched, the screen appears to the user with the static resources. To prevent this situation, adopt an offline-first implementation approach."

Are these offline approaches only applicable for mobile? Or did I misunderstand something? Because that was my understanding, and now when I research it (https://success.outsystems.com/documentation/11/developing_an_application/use_data/offline/), it always refers to "Applies only to Mobile Apps" also. 


Thank you in advance!


2023-10-27 13-43-55
Mafalda Melo Oliveira

"Example: If you want to set a default value in local parameter of your screen but you have logic to decide which value you will set. "


In this case, can you use logic to assign the value already? Values in aggregates will be assigned later when onInit finishes. However, I thought that logic would also be implemented later on, for example, when it is onready. Perhaps it's not quite like this.. 


The guided paths and documentation are a little theoretical, and I feel like there could be more practical information and examples. For example, "On parameter change" seems obvious and there is an exercise about it.

2023-08-28 07-00-10
Paulo Torres
Champion
Solution

For your first question, if you don't want to show UI before the data is prepared from the server, you can use this approach (Can be done with IF also).

2023-08-28 07-00-10
Paulo Torres
Champion

I was speaking about situations where you don't need nothing from the server, like this: 

If you need to define something with conditions based what yoiur query return, you have to use this OnAfterFetch for that.

On parameter change: Used on WebBlocks when you have input parameters and if these inputs changed normally you have to execute something (Refresh query for example).

Note: Don't use events to go to the server and respect the warning that platform give :)

2023-10-27 13-43-55
Mafalda Melo Oliveira

Thank you for your help! 

I find the On parameter change to be the easiest. Your examples have been very helpful, and I think the rest will come with experience and necessity. Thanks again !

2023-08-28 07-00-10
Paulo Torres
Champion

For sure the experience and challenges will help :)

2023-08-28 07-00-10
Paulo Torres
Champion
Solution

For your first question, if you don't want to show UI before the data is prepared from the server, you can use this approach (Can be done with IF also).

2023-08-28 07-00-10
Paulo Torres
Champion
Solution

OnInit is very useful if you want to assign values into a variables for example, create lists etc... Everything in client side you have to prepare before to go to the server (Queries, API's) and also values you need on the screen.

Example: If you want to set a default value in local parameter of your screen but you have logic to decide which value you will set.

Another example:

2023-10-27 13-43-55
Mafalda Melo Oliveira

Hello @Paulo Torres 


Firstly, thank you for providing the examples!

Could you also provide some examples of actions and tasks that can and should be done for the other events? It would be greatly appreciated.


I have another question:

"Even before the data from the aggregates and the data actions is fetched, the screen appears to the user with the static resources. To prevent this situation, adopt an offline-first implementation approach."

Are these offline approaches only applicable for mobile? Or did I misunderstand something? Because that was my understanding, and now when I research it (https://success.outsystems.com/documentation/11/developing_an_application/use_data/offline/), it always refers to "Applies only to Mobile Apps" also. 


Thank you in advance!


2023-10-27 13-43-55
Mafalda Melo Oliveira

"Example: If you want to set a default value in local parameter of your screen but you have logic to decide which value you will set. "


In this case, can you use logic to assign the value already? Values in aggregates will be assigned later when onInit finishes. However, I thought that logic would also be implemented later on, for example, when it is onready. Perhaps it's not quite like this.. 


The guided paths and documentation are a little theoretical, and I feel like there could be more practical information and examples. For example, "On parameter change" seems obvious and there is an exercise about it.

2023-08-28 07-00-10
Paulo Torres
Champion
Solution

For your first question, if you don't want to show UI before the data is prepared from the server, you can use this approach (Can be done with IF also).

2023-08-28 07-00-10
Paulo Torres
Champion

I was speaking about situations where you don't need nothing from the server, like this: 

If you need to define something with conditions based what yoiur query return, you have to use this OnAfterFetch for that.

On parameter change: Used on WebBlocks when you have input parameters and if these inputs changed normally you have to execute something (Refresh query for example).

Note: Don't use events to go to the server and respect the warning that platform give :)

2023-10-27 13-43-55
Mafalda Melo Oliveira

Thank you for your help! 

I find the On parameter change to be the easiest. Your examples have been very helpful, and I think the rest will come with experience and necessity. Thanks again !

2023-08-28 07-00-10
Paulo Torres
Champion

For sure the experience and challenges will help :)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.