Could someone confirm how the RunJavaScript action works in comparison to screen-level JS? 

If have RunJavaScript in the preparation do a 'button click' will it work the same as having a 'window.onload button click' at screen level? 

Basically, I need to know if the JS in preparation will allow the screen to finish loading or if it will wait for the called action to run?


Hi Craig,

JavaScript runs on the client side and preparation has the name indicates prepares the screen to be rendered. Since the screen itself still doesn't exist  and it still wasn't sent to client you can't execute Javascript. In other hand having the js in screen level linked to window.onload event it will run when the page finish to be rendered.



Preparation runs before the screen is rendered, so I'm not sure why you would run JS in a preparation, or even whether it would work.

Can you describe the use case you're trying to support?

Thanks. It does 'work', but i am trying to understand how it works as its probably not doing what i want it to.

I will try to explain what I'm trying to acheive. I have a homescreen which also has a web block. I want the page structure to load and then to lazy load the data (both in block and screen) and then refresh the UI. Separate data queries for the screen and the web block. 

- The web block has an onload event which runs the JS to click a button and bring in the data. It works perfectly.

- Trying to do the same with the screen itself, i.e. have the JS at screen level do a button click, but there seems to be some conflict with the web block JS as it doesnt run unless i remove the web block's JS.

Hope that makes sense. I'm look for a way to have both buttons clicked after page loads (one in screen, one in block).

So, if it were me, I would probably add something like this to the Screen JavaScript property:

$(function() {  // Call .click() here });

That will execute when the page has finished loading, and if the button on which it's called is set for AjaxSubmit, will trigger the action and Ajax Refresh the related controls, which sounds like what you're looking for.

I'm not sure whether that's optimal from an architectural standpoint, but it's where I'd start exploring, rather than using the Preparation for what is essentially a client-side operation. The resulting code will be simpler and easier to debug and understand.

Hope that helps!

Thanks, as said though, it isn't working this way while I have the similar JS on the web block. Not sure why..

Is there some limitation that prevents two 'onload' scripts to run on the same page?

Hi Craig,

That is a JS limitation. You can only assign 1 function to each event.



This would be why you use jQuery's .ready(), rather than the browser's window.onload. jQuery will happily run more than one .ready handler via the syntax I suggested. jQuery is already available as part of the platform, so you don't need anything extra to take advantage of this.