In most Perspective scripts, you are given a reference to a component object (often in the form of a self parameter). The object is given in component scripts, but has several methods and properties associated with it to help traverse to the other objects in a Perspective View or get values from the Session.
Object Traversal is limited to a single view. If a script needs to reference a component in a different view, or there is a possibility that the hierarchy of the view will change, then Message Handling should be utilized instead.
Object Traversal Examples
If you want to get other component properties in a view while scripting, you can use the above methods and properties to move around the View.
These examples assume you have the following structure/components in a View:
- Button 1
- Text Field 1
- Container 2
- Text Field 2
- Container 3
- Text Field 3
- Container 4
- Button 4
- Text Field 4
Perspective components contain several shared methods. This section details such methods. Some methods are only available to certain types of components. In these cases, the description for the method will state any limitations.
refreshBinding function can be used to manually fire a binding, and is designed to be used on bindings that can poll (like query and Tag history bindings). In these instances, using refreshBinding in lieu of polling can save Gateway resources. The refreshBinding() function takes a string as a parameter, corresponding to the property that should be refreshed:
focus method can be called by a component to request focus in a view. This is useful if you wish to control where keyboard input is directed after a particular action.
Due to the nature of focus, calling the
focus method is only effective on components that can have focus. Input components such as the Text Field and Numeric Entry Field components can gain focus, but Display components like Labels and Images can not gain focus.
Perspective offers the option of configuring your own methods for a component. To configure a custom method:
- Right-click on the desired component in the Designer, and select Configure Scripts...
- Under Custom Methods, double click on Add method...
- Enter a Name for your method, which will be used to call the method.
- Enter any number of Parameters your method will need, separated by commas.
Add code to implement your method.Note: A self object is provided in every custom method, but should not be provided as a parameter when calling the function.
- Click OK to commit your method.
To call this method, use: