Templatable programme steps

Programme step templating allows you to take your programme step JS function and associated module data class value (if applicable) and save for use in other programmes really easily.

Any step that allows for a JavaScript input will have the option for templating. Templating and saving code can be great for productivity if reproducing the code across many programmes.

Writing custom JavaScript

By default, any programme step that includes the use of a JavaScript function will be using a 'custom' template (see first screenshot in this document, under 'template select' label). What this means is that the JavaScript you write is not being used as any saved template. The code itself is independent and only applies to the step its being used on.

If the code your writing is unique to the step your working on and its unlikely that this will need to be used in other programmes, then keeping the 'template select' dropdown on 'custom' is best. On the other hand, if you think the code would be re-used somewhere else you can make it as a template (see below 'JavaScript step templating').

JavaScript step templating

Below is an example of a function for waiting until 5 days after a customers date of birth:

This function alongside its 'module data class' value may be really useful to use in other programmes so that's why we may choose to template this up. You would save the template by clicking the 'Save as template' button found at the bottom of the function template input field. After doing this here is the popup modal that would appear:

Here you would give your templated code a name. This name is just for reference and does not affect any of your code. Whilst this modal is visible, you can also review your code before clicking the 'save' button.

You will now notice that on the programme step, your template has been pre-selected from the 'template select' dropdown and also that your code is no longer editable

Now that your code is saved as a template, it can be used in any other 'wait until' steps just by selecting it from the 'template select' dropdown.

Templatable fields

Templatable fields make use of mustache tags. It should be common practice to wrap any mustache tags your using in double quotes like this: "{{newTemplateField}}"

If you require a number value from your mustache template vs a string, ensure to use one of the JS string to number conversion functions to change the value such as 'parseInt' or 'parseFloat'.

If you include mustache tags in your javascript code, a new section will show your tag with an input field above the code like so (highlighting of this area for demonstration only):

By creating templatable fields you are allowing for quick edits to the function in future without diving into the code itself. This also allows for anyone with not much JavaScript experience to edit key functionality.

You can create as many templatable fields as you see fit with no limits. Fields like this can be created for both custom code and for templated functions.

Template manager

The template manager is used to create delete and update function templates. The link for the template manager can be found both from the programmes main page and the programme editor pages.

In the above screenshot we have used the search filter to find a particular function. You can search both by name and by the type of programme step the function is associated with.

You can create a new template using the first or top set of inputs. Name, step type and function are mandatory fields. 

Once step type has been associated with a function it cannot be updated later on.

Deleting Templates

When either selecting delete or update on a template a usage check is performed in the background. This will check if a programme is currently using the selected template you are amending/deleting.

You cannot delete templates that are used in any programmes (regardless of programme status). If you attempt a delete on a template that is being used in a programme, the following modal will appear:

Each programme where the template is used will be listed and linked to. You can delete this template only if you go through each usage, remove the programme step/referenced code and save the changes on the associated programme.

If no usages are found when attempting to delete a template, you will have a confirmation which will ask if your sure you would like to delete.

Updating Templates

If changes are made to a template and you decide to update it, a usage check will be performed in the background. If the template is used in any programme you will see something similar to the following:

Here you should carefully and manually check each programme listed to see if your updated code would cause issues. If your sure that it wont, you can go ahead and click "Yes I'm sure" to update the template.

If no usages are found your template will just be updated and no modal will be presented.

Still need help? Contact Us Contact Us