I have a SSJS running in the BeforePageKoad event. As the last step of the SSJS I want to do a partial refresh. In my script I have this line of code:
view.postScript("partialRefreshGet('#{id:panelAll}')")
When it executes I get an error that says partialRefreshGet is undeffined. I'm guessing I'm missing something in the format of the call, but as I understand it this should work.
Anyone done something like this before.
If I leave this code out then do a manual refresh of panelAll from a button everything works correctly.
You can't use before view.postScript in the beforePageLoad. Try moving it to afterPageLoad or beforeRenderResponse. I recently ran across the same issue.
http://notesspeak.blogspot.com/2013/08/viewpostscript-only-works-for-certain.html
Here is a summary where you can use view.postScript():
- onClientLoad = nothing happens
- beforePageLoad = XSP error
- afterPageLoad = WORKS!
- afterRestoreView = nothing happens
- beforeRenderResponse = WORKS!
- afterRenderResponse = nothing happens
To know why this is happening, read Tim Tripcony's comment at the bottom of the blog post.
Just add a scriptblock to your XPage with the required partial refresh.
EDIT:
<xp:scriptBlock id="scriptBlock2" rendered="#{javascript:requestScope.doRefresh}">
<xp:this.value><![CDATA[
XSP.addOnLoad( function(){ XSP.partialRefreshGet('#{id:panelAll}') } );
]]>
</xp:this.value>
</xp:scriptBlock>
In your beforePageLoad you then set the requestScope variable if required.
This answer might be a little too late, I hope it would be useful for someone.
So, the simple answer is to use the following SSJS to refresh another component:
view.postScript("XSP.partialRefreshGet('#{id:
Component ID
}')")
However, I've had my share of trouble trying it, and as Tim Tripcony suggested, the code seems to be running too soon, while the browser is still receiving the 1st refresh, and it doesn't work. So I tried attaching it in an OnLoad event like so:
view.postScript("XSP.addOnLoad(function() {XSP.partialRefreshGet('#{id:
Component ID
}')})")
But that also didn't work. So I did it the old way and it worked by letting the script work in a different thread using setTimeout() like this:
view.postScript("setTimeout(function(){XSP.partialRefreshGet('#{id:
Component ID
}')}, 1)");
and it's working like a charm!