Snippets
Snippets are reusable parameterized pieces of code that can be used in field transformations as well as other parts of your project that incorporate code. Snippets allow developers to write a section of code once and then use it in various parts of the TimeXtender Data Integration solution wherever appropriate. Snippets not only save time but can also simplify the maintenance of code should any changes in the future be needed to it after it has been deployed.
Snippet Categories
- SQL
- DAX
- Qlik
- Tableau
Adding a Snippet
The steps to create a snippet are similar for the various snippet types. The following example of creating an SQL Snippet illustrates the process of adding a snippet.
- On the Tools menu, click Snippets. The Snippets window appears.
- Click Add and click SQL Snippet. The Create SQL Snippet window appears.
- In the Name box, type a name for your snippet.
- (Optional) In the Description box, type a description of what the snippet does.
- Enter the script in the Formula box. For any variables (lYEAR] in the example above), highlight the variable and then click the Add Parameter button to add the highlighted text as a parameter name under Parameters. If parameters include brackets around them, make sure that the brackets are included in your parameter name below.
- Under Parameters, change the Type to match what the variable represents. The various parameter types are as follows:
- Table
- Field
- Database
- User Defined Function
- Stored Procedure
- Value
- Click OK to save the snippet.
Using a SQL Snippet
SQL snippets can be used in a number of situations.
- To use a SQL snippet in a Field Transformation, right-click the field, click Add SQL Snippet Transformation and click on the SQL snippet you want to use.
- OR -
To use a SQL snippet as a stored procedure , right-click Stored Procedures and click Add Snippet Stored Procedure and click on the SQL snippet you want to use.
- OR -
To use a SQL snippet as a used defined function, right-click User Defined Functions and click Add Snippet User Defined Function and click on the SQL snippet you want to use.
- OR -
To use a SQL snippet as a script action custom step, right-click Script Actions and click Add Snippet Custom Step and click on the SQL snippet you want to use. - In the window that appears, map the available fields to the parameters in the snippet. Drag the field(s) from the list on the right and drop the field on the Object Name/Value column for the relevant variable. The Object Name/Value column and Variant column will populate automatically.
- Click OK.
Using a DAX Snippet
DAX Snippets can be used in the creation of Custom Measures and Calculation Group Items in Deliver Instances that have Tabular or Premium Power BI endpoints. The steps are similar for Custom Measures and Calculation Group Items.
The following example outlines the usage of a DAX Snippet for the creation of a Calculation Group Item.
- Right-click an existing Calculation Group and select “Add Item”.
- Select an appropriate Endpoint, either Tabular or Power BI Premium.
- Enter a Name for the new item.
- Click the “Add Snippet” button.
- Select the appropriate DAX Snippet from the list of available snippets.
- Map the Parameters to fields available from the tables on the right.
- After mapping the parameters, click the “Show Translation” radio button to view the translation of the script with the fully qualified parameter references.
- Click OK to save the Calculation Group item.
Changing a Snippet
When an object has been created using a snippet, changes cannot be made to the object content or formula directly. In order to change the object content, the snippet that was used to create the object needs to be amended as described below.
Right click on the object that uses the snippet and choose “Edit <object type>” from the context menu, as in the following “Edit SQL Snippet Transformation” example.
Click “Change Snippet” to change the snippet that is being used and then click OK.