This is a practical reference example of how to use the ExceutePS function from a ViewModel. There are many possible uses, but this one is fairly descriptive.
Need: Look up all the objects with the same value as one particular object. Maybe the user wants to know if something is unique or not…
Model:
ViewModel:
We set the vValueToMatch to the Attribute1 of the ViewModel root Thing. Then, we call the ExecutePS, stating that it will get a result collection with the objects of type Thing if it runs the expression found in OutOfLoopToAvoidStdFetch.col1. We collect this result and add the objects to a list we added as a variable – vMyList.
The list can act as a root for Grid in the UI.
If we have a million Thing objects in the database, this ViewModel will only load the ones with the same attribute1 as the Thing object we started with.