About the Creation of Shortcut Methods

A shortcut method lets you avoid a heavy structure of nested loops.

You can convert each nesting of loops of any depth using a shortcut to a simple loop, if:

  • The nesting of loops is a succession of returned and received variables (that is, no loop contains several loops for a level).
  • The intermediate variables do not matter in the template.

This page discusses:

Shortcut Method

To avoid complex nested structures in the template editor, you can create shortcut methods.

A shortcut method helps you convert a nesting of loops of any depth in a simple loop, as follows:



For the definition of a shortcut method, the internal names of the methods to be called must be combined using the member access. For more information, see Defining OTScript Methods in Templates, OTScript Method Presentation, and Member Access.

Example

The path from an object to the interesting terminal data can be long and this can have an impact on the readability of templates.

Extract of Template with Nested Loops


In this example, the aim of the nested loops is to reach a specific list of data.

Recommendation: Create a shortcut method to reduce the number of nested loops.

You can write the following method to reduce the previous template:

METHOD RFLVPMLogicalReference.getPipingConnections() -doc : 
   getAllSubComponents.As_rel_Piping_Logical_Instance_Entity.As_rel_Piping_Logical_Part_Inst.GetConnexionList
LABEL "Get Piping Connections";
To define the body of the method, combine successively the internal names of the methods of each loop. The following table lists the methods used for the example:
Methods in Loops Associated Internal Name
Get All Sub-Components getAllSubComponents
As Piping Logical Instance Entity As_rel_Piping_Logical_Instance_Entity
As Piping Logical Part Inst As_rel_Piping_Logical_Part_Inst
Get Connection List GetConnexionList

You can use this shortcut method to create the following template, which is equivalent to the previous template:

Reduction of the Number of Nested Loops



Note: The creation of shortcut methods can:
  • Improve the readability of templates by avoiding deep nested loops.
  • Enable you to define sort criteria to sort loops on a particular type of object. For more information, see About the Sortings of Loops.