RunServerSideViewModelNow lets you trigger a named ServerSide ViewModel from a client ViewModel action when you need the server-side work to be checked without waiting for its next scheduled interval.
A ServerSide ViewModel is implemented by MDrivenServer and normally runs on a defined periodic schedule. Use this operator when a client action changes state that the ServerSide ViewModel discovers through its server-side PS Criteria, performs actions on, and saves.
For example, a client can save an object marked as ready for sequence-number assignment, request that the ServerSide ViewModel check for work now, and then refresh to obtain the updated object.
Syntax
selfVM.RunServerSideViewModelNow('<ServerSideViewModelName>')
Call the operator on selfVM, the ViewModel variable available in a ViewModel context. Supply the name of the ServerSide ViewModel that should be checked.
When to use it
Use RunServerSideViewModelNow when all of the following apply:
- A ServerSide ViewModel already performs the required work on a schedule.
- A client action has created or changed data that meets the ServerSide ViewModel's server-side PS Criteria.
- Waiting until the next polling interval would make the client experience unnecessarily slow.
The operator requests that MDrivenServer check the named ServerSide ViewModel for execution need as soon as possible rather than waiting for the normal interval.
Client-to-server pattern
Use the following sequence in the client action:
- Set the state that makes the object eligible for server-side processing.
- Save the ViewModel changes with selfVM.Save. Saving makes the changed state available to the server-side processing.
- Call
RunServerSideViewModelNowfor the ServerSide ViewModel that detects the state. - Refresh the client ViewModel to read the data after the server-side work has updated it.
selfVM.Save;
selfVM.RunServerSideViewModelNow( SomeClass.ViewModels.SomeServerSideViewModelWeWaitFor );
selfVM.Refresh
In this example, SomeServerSideViewModelWeWaitFor is the ServerSide ViewModel responsible for finding the saved object and performing the follow-up work. The final selfVM.Refresh reloads the ViewModel data so the client can show the result, such as the newly assigned sequence number.
Important considerations
- This operator is intended to reduce the delay caused by periodic polling. The ServerSide ViewModel must still be configured to find the relevant data through its server-side PS Criteria and to perform and save its actions.
- Save before requesting the server-side check. Otherwise, the condition that the ServerSide ViewModel searches for may not be persisted when it runs.
- Refresh after the request when the client must display values that the server-side processing changes.
- Keep the ServerSide ViewModel name aligned with the model. In the example, the
ViewModelsreference is used rather than a hard-coded name.
