Partial refresh change panel depending on whether backend document has been updated

114 views Asked by At

I have a booking form that needs to check to see if a booking is still available when someone clicks the book button. If it is available I would like the SSJS code behind the button to process (this then updates some values on the booking form), however if on checking the booking it is no longer available, I would like to do a partial refresh of a different panel (a panel within the main panel), so the user is advised that that it is not available and they can go find another suitable appointment (this has been done by having different panels available).

In order to do this, I have programmed the element to be updated within the partial update of the button on the form.

var tbooked = document1.getItemValueString("booked");

if (tbooked =="Free") {
    return 'mainPanel'}
else {
    return 'dialogPanel'}

I have then added the following code to execute when the button is selected.

var tbooked = document1.getItemValueString("booked");

if (tbooked =="Free") {
    Set a bunch of viewScope variables.
    Also save the document
}

It appears as though the code to return the panel to be updated is not executing the 'else' portion of the if then - am I using this incorrectly?

1

There are 1 answers

0
Knut Herrmann On BEST ANSWER

You put the first code snippet into refreshId property of button's event handler. This code gets executed before the rendered page gets send to browser. This is too early for your case as at this time the booking is always free.

The easiest approach would be to do a full update.

If that's not feasible then use XSP.partialRefreshPost(id, ...) and XSP.partialRefreshGet(id, ...) to try to book and if successful to refresh mainPanel and otherwise dialogPanel.