Change Script on View Params

Hello,

I am facing a strange behavior or maybe it is a design problem/misunderstanding how parameters should be used. I am opening a dock view with an ID parameter from the main view. This ID parameter has a change script that should load the details for that particular ID or if it -1 it should create a blank/new record. Further, when the dock is opened the change script loads some data for dropdown fields.

I realized that when I open a dock with a specific ID, then close it and open the same one again, it will not execute the change script again since the value did not change. Even after reloading the entire page, it does not execute the change script again. It seems that the value is retained in the memory

So, what would be the best way to open a dock view with an ID and load additional data. I already added another parameter which always contains a random value and added the change value script to it but I don’t like it because I am not sure whether it is guaranteed that the ID field is already filled with the new value when the change script is executing.

Also, what would be the best way to deal with the initial values in the parameters that were in there from the designer. Can those somehow be initialized. I tried to use the startup script but it does not seem to execute when the docked view is opened

Thanks, Carsten

Docks are never closed as such, they are simply pushed out of the visible viewport, hence they only trigger any on opened scripts once. You should be able to pass parameters to the dock though to set your ID

I am passing the ID as a parameter. The problem is if the ID value does not change the change value script does not get executed. I need to be able to execute it every single time. Is there a different event or a complete different way that i could use in these cases?

Don’t use a parameter. Use a custom property, and send a message to the dock to set it.

I agree that sending a message to force an update is probably the best idea.

# order matters here because you want the dock to be in place and available to hear the message
system.perspective.openDock("DOCK_ID", params={"some_param": 1})
system.perspective.sendMessage("UPDATE_DOCK_BINDINGS", scope="page")

Then the relevant components of the Docked View should have listeners configured for an UPDATE_DOCK_BINDINGS Message Handler which does the following:

self.refreshBinding("props.<some_prop>")
1 Like

Thanks everyone, it works smoothly :slight_smile:

@pturmel @cmallonee

Remind me again, why can’t you just pass the new param value in via openDock? Why do you mention using refreshBinding as well? I remember something about this but it’s been a while since I’ve touched docked Views…

The concern here is that the value of the param is not changing, and therefore the change scripts are not executing as the docked view opens/closes.

OH, I completely missed that :slight_smile: That makes sense then

I’m experiencing the same issue, the parameter is not updating on the view when using the system.perspective.openDock function after the first open and close.

The parameter values being passed to the system.perspective.openDock are different but the parameter values on the view are not updating.

I’m using the fix suggested by pturmal , system.perspective.sendMessage() to send the data to the view.