selfVM gives you access to the running ViewModel from an OCL expression or action. Use it when you need to save, refresh, invoke ViewModel behavior, inspect ViewModel state, or work with the ViewModel rather than the current business object.
What selfVM refers to
selfVM is a built-in ViewModel variable. It references the ViewModel that holds the objects currently being worked with.
Do not confuse it with self:
| Expression | Refers to | Use it for |
|---|---|---|
self
|
The object in the current expression context. | Reading or changing attributes and associations of that object. |
selfVM
|
The running ViewModel. | Running ViewModel operations, saving, refreshing, inspecting state, and accessing the object that opened a rooted ViewModel. |
For example, an action column placed in a detail nesting has a self that refers to that detail object. selfVM still refers to the ViewModel containing that nesting.
You can inspect the variables and members available in a particular expression context in the OCL editor or Action Editor. This matters because available variables can differ when a ViewModel is used for a user interface, an API, or a report. For a broader explanation of self, vCurrent, and other variables, see Documentation:ViewModel variables.
Common tasks
Save the changes made in the ViewModel
Use selfVM.Save to commit changes made in the ViewModel to persistent storage.
selfVM.Save
Before saving, you can inspect the objects that will be saved through selfVM.DirtyList. To abandon all changes made through the ViewModel, use:
selfVM.DirtyList->DiscardChanges
See Documentation:OCLOperators Save and Documentation:SelfVM.DirtyList for the save and discard behavior.
Run fetch hints for a list
Use selfVM.ExecuteFetchHints(aList) after you have populated a list outside the normal seeker flow and want its fetch hints applied.
A ViewModel nesting whose name starts with FetchHints provides the fetching hints. The columns in that nesting are executed for lists returned through seeker logic. Call ExecuteFetchHints explicitly when you create the result list yourself.
For example, this action clears a result list, adds the selected sales articles, and then applies the fetch hints to that list:
vSeekerResult->Clear;
Singleton.oclSingleton.User.FavoriteArticle->select(fa|
fa.Filter.SqlLike(vFavFilter+'%') or vFavFilter.IsNullOrEmpty
).FavoriteArticles->collect(a|
let sa=a.SalesArticles->select(sa|sa.MarketingCompany=self)->first in
(
if sa.isnull then
vSeekerResult
else
vSeekerResult.Add(sa)
endif
)
);
selfVM.ExecuteFetchHints(vSeekerResult)
See Documentation:Efficient ViewModel fetch for the complete pattern and its purpose.
Execute ViewModel actions
Use selfVM.ExecuteAction when an OCL action needs to invoke an action on the running ViewModel. Use selfVM.CanExecuteAction when you need to determine whether an action can execute before invoking it.
The exact members available depend on the expression context. Use the Action Editor to select the operation and supply its arguments rather than assuming an action signature.
Access the object that opened a rooted ViewModel
selfVM.RootObject returns the object instance used to open the current rooted ViewModel. The root reference cannot be changed while the ViewModel is open, but you can change attributes on that object.
Because selfVM is available in every ViewModel, the root object has no fixed static type. Cast it to the type you expect before accessing its attributes.
selfVM.RootObject->notEmpty
The expression above checks whether the ViewModel has a root object.
selfVM.RootObject->safeCast(Thing).SomeString:='a new value'
See Documentation:OCLOperators RootObject for details.
Identify how the ViewModel is being used
selfVM.DisplayMode identifies the current usage of the ViewModel. It can have these values:
enum DisplayModeEnum {
UINormal, UIModal, UIPopup, Technical,
RestPost, RestGet, RestPatch, RestPut, RestDelete
};
For example, ViewModels used by templates, transforms, deep clones, server-side execution, asynchronous tickets, reports, or Tajson use Technical. MVC-rendered pages also use Technical. WPF and Turnkey user interfaces use UINormal, UIModal, or UIPopup.
See Documentation:OCLOperators DisplayMode for the full usage guidance.
selfVM members
The following operations and properties are available on selfVM. Availability and accepted arguments are context-sensitive; use the OCL editor or Action Editor to inspect the member in the place where you will use it.
| Member | Category | Purpose |
|---|---|---|
ExecuteFetchHints
|
Operation | Applies configured fetch hints to a list. See Documentation:Efficient ViewModel fetch. |
Save
|
Operation | Commits ViewModel changes to persistent storage. See Documentation:OCLOperators Save. |
ExecuteAction
|
Operation | Executes a ViewModel action programmatically. |
CanExecuteAction
|
Operation | Checks whether a ViewModel action can execute. |
Search
|
Operation | Runs ViewModel search behavior. |
ImportTabSepData
|
Operation | Imports tab-separated data. |
Refresh
|
Operation | Refreshes the ViewModel. |
ExecutePS
|
Operation | Legacy persistent-storage evaluation operation. Use <Class>.PSEval instead. See Documentation:How to use the ExecutePS function in selfVM.
|
PSExpression_Refresh
|
Operation | Refreshes a persistent-storage expression. |
RestGet, RestPost, RestPatch, RestPut, RestDelete, RestDownload
|
Operations | REST-related ViewModel operations. |
JSonToObjects, XmlToObjects
|
Operations | Converts JSON or XML to objects. |
XsltTransformXml, XmlValidateWithSchemas
|
Operations | Transforms or validates XML. |
ViewModelAsJSon
|
Operation | Produces a JSON representation of the ViewModel. |
GetGridAsTabSepData
|
Operation | Produces tab-separated data from a grid. |
SuspectExternalUpdateInvalidate
|
Operation | Invalidates the ViewModel when an external update is suspected. |
RunServerSideViewModelNow
|
Operation | Runs a server-side ViewModel immediately. |
Navigate
|
Operation | Performs ViewModel navigation. |
ShowActionMenuForCurrentInNesting
|
Operation | Shows the action menu for the current object in a nesting. |
ExecuteCurrentActionAgainOnce
|
Operation | Requests one repeat execution of the current action. |
SysDocBatchZip
|
Operation | Creates a system-document batch ZIP operation. |
Download(filename:string,blob)
|
Operation | Downloads a blob using the specified file name. |
ViewModelName
|
Property | The ViewModel name. |
DirtyList
|
Property | Changed objects that selfVM.Save will save. See Documentation:SelfVM.DirtyList.
|
ListActions, Nestings, Styles
|
Properties | ViewModel action, nesting, and style collections. |
DisplayMode
|
Property | The current ViewModel usage mode. See Documentation:OCLOperators DisplayMode. |
LogEntry
|
Property | The ViewModel log entry. |
RootObject
|
Property | The object used to open a rooted ViewModel. See Documentation:OCLOperators RootObject. |
