Defining OTScript Methods in Templates

Even if you are not an Administrator, you can define your own reusable OTScript methods and types, if those provided in the Data tab are insufficient to your needs.

Important:
  • These methods are only available in the current template.
  • A subtemplate call does not show extra methods, so avoid using conflicting types or method names.

See Also
Managing OTScript Methods
About the Creation of Shortcut Methods
OTScript Language
  1. From the template editor, select the OTScript tab.


  2. To define some OTScript code in the coding area, you can do any of:
    • Enter or copy OTScript code corresponding to one or more methods.
      Note: To find the internal name of a method, hover over its name in the Data tab or hover over the loop that calls it.
    • Drop a method from the Data tab into the coding area.
    • Define the custom methods getConnectedIds and getConnectedComponents based on the “Change action” method to return all child components of a physical component.



  3. To compile and save the code, click Save .

    Note: If OTScript finds an error, it marks the line. Hover over the mark to see the error message. OTScript shows only the first error.

    Correct errors one by one to be able to generate reports.

Result:

Methods defined in the OTScript code appear in the Data tab of the template editor. If no category is indicated in the code, methods are presented in the Extensions category.

You can insert these methods, as usual, in your current template.