Servicely Capability
Templates
11 min
within servicely it is possible to create templates can be used for two main purposes these purposes include the ability to pre set records on a record based on hardcoded values or values (such as making a record a priority 1, setting an assignment group and classification (and more)) or create a record based on a schedule (such as a monthly security patch task) currently these are only definable by system administrators (as they can be script) and are global for agents on that record type regardless of the purpose however, you will still need to create the system template definition to be used in both circumstances template definition when creating a template, one of the first steps is creating a template to do this, you can go to either the templates list, or create a new template directly, as found in the administration menu, under the templates section (you will notice there are some out of box examples there for some administrative purposes) once you are there, you can start creating your template definition with the following details field name description example name this is the name of the template this is what will be show in the dropdown when client selectable for users to select example incident template table this is the table where this template will be used incident active whether or not this template can be used yes (true) client selectable this decides whether or not it can be used on the form itself, or only used for scheduled templates note that a template can technically be used for both, when this is flagged as yes yes (true) order where this shows up in the list (when there are multiple with the same name) not mandatory 1 description a short description about what this template does this template helps set the priority and client journal based on details in the content system template values this is a list of values this template sets when being selected, or being run as a scheduled template to have new values, press the “new” button (add/remove is only used if for whatever reason you unset the parent of the value record) see below for details system template values to allow a system template to set the fields on the table described above below are the fields and their definition and how they can be used field name description example template this is the template that this value is connected to noting that a system template value can only be connected to one system template example incident template field this is the field on the table that this value will set clientjournal advanced whether or not this needs to be an advanced / scripted value noting that if this is ticked, it will use the last variable defined in the script field, rather than the value defined see below for examples active whether or not this template value will be used in the template when used yes (true) overwrite existing value whether or not when this template is selected it will overwrite any value entered previously yes (true) order not used currently, but helps when setting values from a backend processing perspective 10 value this is the hardcoded value that can be used to set a value on a record (such as an id, choice value, string or otherwise) in scheduled template examples, it can accept a parameter with the ${} braces this will be exampled further in the document see below for examples script this is server script script to help set the field dynamically based on values on a record note that the last line of the script should be the value it should equal (such as the below example) see below for examples system template value examples as templates can be used for a variety of purposes, we have provided some examples as to what to set fields to achieve certain purposes example 1 hardcoded values for fields in situation where you want to set a field to a “hardcoded” value (such as an assignment group to a specific value, priority to a specific priority, short description to specific text) and more to achieve this you would want to advanced no (false) value this will be dynamic based on what type of field some examples are for choice fields this needs to be the choice key you can find out the choice key by looking at the field definition and the field specific settings tab such as, for priority it wouldn’t be “1 critical” the template value would be “1” or for source, it wouldn’t be “phone”, it would be phone for reference fields this would be the id of the reference record for string fields it is simple the string you want to use example 2 parameterised values from scheduled templates the way parameters are passed in will be described in the “scheduled templates” section, however, to achieve this you would want to advanced no (false) value the parameter name will be done within ${} noting that the parameter is specifically passed in via the scheduled templates section, which will be described below example 3 scripted values the third example is scripted values as this is server side scripts, you can do lookups, look at the record to template values and more what we have typically found with customers is using this for a templated response and replacing it with items like the requestor’s name to achieve this, you would advanced yes (true) script this is server side code it should be noted that you should review table api (server) docid\ latfchaaxu1wqcrr1vn0p if you want more detail, but to help describe this, you can refer to fields on the current record and you should often check if values exist to help explain this, we have developed the example to provide this end result in this example, it takes the requestor’s first name and provides a html string, to make sure it is formatted correctly also, as described above, you want to make sure that the last item in the script is the variable, as pointed out below the reason as to why we have escaped some text here, is as the journal field is html, if we included braces, it would format it as html, so this ensures that in the template it would include the <> when the requestor does not exist you can also make use of parameters defined in a scheduled template’s context script, on a template value’s script, example below mapping to a multi reference field referencing the cmdb table below shows an example of a scheduled template’s context script returning the parameters to use on a template’s script shown above scheduled templates in addition to using templates from an agent point of view, templates can also be scheduled, which would take the template and its values and creates a record with that table name based on a schedule defined it can also take parameters from the scheduled template, to allow it to be more dynamic (such as if you want to script it) to create a scheduled template, go to the templates section under the administration menu item once here, you can populate the following fields to achieve what you want to achieve field name description example name this is the name of the scheduled template this is not used for anything other than identifying what it is for example monthly task schedule this is the schedule as to when it runs such as, every day, every week, every hour, etc note that the value will be in the format of a “cron” expression, but you do not need the cron expression to make it the below example is to run this template job at 1 am every 1st of the month noting that this runs in the system timezone 0 0 1 1/1 ? active whether or not this scheduled template is running yes (true) run as this is the user which this template runs noting that they need to have permission to make that record and will be used as the person who created the generated record admin administrator templates these are any of the system template definitions that you wish to run at the scheduled time example incident template context script this is the script that can pass parameters to the generated template even if no parameters are used, we suggest including answer = \[{}]; if you want to add any records to the scheduled template record itself (such as a company field) you can then access these values via “current” in the context script to describe the example, you can use each of these parameters by ${details}, ${group} and ${priority} in the values field of the system templates accordingly in this example, it is setting the short description of the generated incident with the name of the scheduled template, setting the assignment group with the id of the group provided and priority to 3 also note that each included template will run once for every object in the array if the array in the example provided here has another object with its own set of “details”, “group” and “priority” parameters, then there will be two records generated using the “example incident template“ template answer = \[{details current name(), group "4aab47e9a5c611edbba30a6baf3a3946", priority "3"}]