OnParametersChanged not always triggered
Application Type
Reactive

Hi community,

At the moment I am running into a problem that causes the OnParametersChanged event to not always be called. It seems to happen randomly, but haven't been able to detect a pattern yet. In the screenshot below I did place the parameters of the screen and the parameters of the webblock. As you can see the input parameter of the webblock is filled correctly but the local variable is being empty. This is because the OnParametersChanged event is not being called in the webblock. In the event I am doing the deserialize of the JSON.

Unfortunately I am not able to share the .oml so I'll try to explain my problem with screenshots.

 

On the page I have 2 local variables. ProductGridParametersJson  and ProductGridParameters.


Next, I have a Client Action (SetProductGridParametersJson) where I serialize ProductGridParameters into a JSON string (ProductGridParametersJson).

In the OnReady of the screen I call SetProductGridParametersJson Client Action (I also did set it in the OnRender of the screen but this does not change anything in the bevahiour explained above). 

If I may believe the description of the OnParametersChanged the event is not being called since the input parameter did not change for some reason? I am not quite sure of why the OnParametersChanged is not always being called since I can see that the input parameter is being filled. Maybe I am doing something completely wrong and I hope I can be guides into to correct direction.

Thanks,

Bart

Hi Bart,

it is hard to help without an oml, so a tip for you to do in your oml : add a console.log displaying the event name and all relevant values in each of your screen and block events and in each spot you do something with the structure or json, and see if you can deduce from that what is going differently than you expect.

you will see for sure when the onParametersChanged did or did not fire, and wether it was after or before screen events were fired, etc.  Maybe you'll discover that the OnParametersChanged is called after all, but some logic error inside it happened.

Ideally, you capture also the other events that you haven't attached any handler too, like the OnInitialize and OnReady and so on of the block, so you actually see first an empty json string being passed, and later at some point a filled one.  Because this is one scenario I can think of : the JSON string was filled like this right from the beginning and then obviously there will not be a ParameterChanged fired.

Dorine

On a side note : I find it odd that you do something with the parameter in an parameters changed event, but not initially.  I feel that somehow same logic should be executed once at the beginning of the lifecycle of a block (such as in the onReady)  I.e. if that block's local variable should always represent whatever is passed into that input json, you create a window of time that this is not the case, to me that feels like your design is fragile, because you are relying heavily on your expectation that the parametersChanged will happen somewhere in the beginning of the block's life.

Hi Dorine,

Thanks for your detailed answer. Sorry for not being able to share a .oml. I get your point. I get your point that it's hard to give a decent answer without an oml. 

Sometimes when you look at a problem you lose the overview. I think this happend in my case and with your tips you did send me on the right track. I did use a console.log as you mentioned but also used the Debugger in OutSystems and I did see for sure the OnParametersChanged did not fire. Then I did take a look at the lifecycle of a application (screenshot below) again since I was thinking this problem had something to do with order of loading things (and I was correct :-P). 

I did find out that my Client Action that is filling the JSON to be passed to the Web Block was being called multiple times before the Render event was taking place. I did reduce this to being called only once when page is done rendering all data and this improved everything a lot! 

I also think you are right with only relying on the OnParametersChanged event. I will see what I can do there.

Thanks!

Bart

Hello Bart,

i have faced similar issue earlier, in my scenario what i discovered is OnParametersChanged will only run when the Value of the input will get change.


Hi Ekjot Singh,

Thanks for your reply! I know that the OnParametersChanged is only being called when a value is being changed. As mentioned in te reply to Dorine I did debug a few things and did find some problems causing this issue.

Best,

Bart

Hi Bart,

it is hard to help without an oml, so a tip for you to do in your oml : add a console.log displaying the event name and all relevant values in each of your screen and block events and in each spot you do something with the structure or json, and see if you can deduce from that what is going differently than you expect.

you will see for sure when the onParametersChanged did or did not fire, and wether it was after or before screen events were fired, etc.  Maybe you'll discover that the OnParametersChanged is called after all, but some logic error inside it happened.

Ideally, you capture also the other events that you haven't attached any handler too, like the OnInitialize and OnReady and so on of the block, so you actually see first an empty json string being passed, and later at some point a filled one.  Because this is one scenario I can think of : the JSON string was filled like this right from the beginning and then obviously there will not be a ParameterChanged fired.

Dorine

On a side note : I find it odd that you do something with the parameter in an parameters changed event, but not initially.  I feel that somehow same logic should be executed once at the beginning of the lifecycle of a block (such as in the onReady)  I.e. if that block's local variable should always represent whatever is passed into that input json, you create a window of time that this is not the case, to me that feels like your design is fragile, because you are relying heavily on your expectation that the parametersChanged will happen somewhere in the beginning of the block's life.

Hi Dorine,

Thanks for your detailed answer. Sorry for not being able to share a .oml. I get your point. I get your point that it's hard to give a decent answer without an oml. 

Sometimes when you look at a problem you lose the overview. I think this happend in my case and with your tips you did send me on the right track. I did use a console.log as you mentioned but also used the Debugger in OutSystems and I did see for sure the OnParametersChanged did not fire. Then I did take a look at the lifecycle of a application (screenshot below) again since I was thinking this problem had something to do with order of loading things (and I was correct :-P). 

I did find out that my Client Action that is filling the JSON to be passed to the Web Block was being called multiple times before the Render event was taking place. I did reduce this to being called only once when page is done rendering all data and this improved everything a lot! 

I also think you are right with only relying on the OnParametersChanged event. I will see what I can do there.

Thanks!

Bart

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