You are viewing documentation for a feature in early preview. The feature is not available for all Laserfiche Cloud accounts and functionality is subject to change.
How to Manually Edit a Deployment Template
The easiest way to add resources to a deployment package is to use the Insert Resource drop-down menu from the Deployment Package Designer.
However, you may have some values hard-coded in your deployment package that you want to edit for added flexibility and for dynamically deploying packages.
Deployment Package Structure
Before editing a deployment package , you should have a good idea of the structure of a deployment template. See a sample template.
You can also refer to the deployment packages's JSON schema. The deployment package schema includes the schema for the package itself, but also includes the schema for each resource.
Using Functions in a Package
Built-in functions can be used to dynamically construct values that can be used during deployment.
Built-in functions
- resourceName: Returns the name of the deployed resource by providing the managed resource name in the package as an argument.
- resourceId: Returns the ID of the deployed resource by providing the managed resource name in the package as an argument.
- resourceVersion: Returns the latest published version of the deployed resource by providing the managed resource name in the package as an argument.
- and: Returns the Boolean AND of its arguments by returning the first empty argument or the last argument. I.e., "and x y" behaves as "if x then y else x." Evaluation proceeds through the arguments left to right and returns when the result is determined.
- call: Returns the result of calling the first argument, which must be a function, with the remaining arguments as parameters. Thus "call .X.Y 1 2" is, in Go notation, dot.X.Y(1, 2) where Y is a func-valued field, map entry, or the like. The first argument must be the result of an evaluation that yields a value of function type (as distinct from a predefined function such as print). The function must return either one or two result values, the second of which is of type error. If the arguments don't match the function or the returned error value is non-nil, execution stops.
- html: Returns the escaped HTML equivalent of the textual representation of its arguments. This function is unavailable in html/template, with a few exceptions.
- index: Returns the result of indexing its first argument by the following arguments. Thus "index x 1 2 3" is, in Go syntax, x[1][2][3]. Each indexed item must be a map, slice, or array.
- slice: Returns the result of slicing its first argument by the remaining arguments. Thus "slice x 1 2" is, in Go syntax, x[1:2], while "slice x" is x[:], "slice x 1" is x[1:], and "slice x 1 2 3" is x[1:2:3]. The first argument must be a string, slice, or array.
- js: Returns the escaped JavaScript equivalent of the textual representation of its arguments.
- len: Returns the integer length of its argument.
- not: Returns the Boolean negation of its single argument.
- or: Returns the Boolean OR of its arguments by returning the first non-empty argument or the last argument. I.e., "or x y" behaves as "if x then x else y". Evaluation proceeds through the arguments left to right and returns when the result is determined.
- print: Returns the value using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string. "print `a` `b`" returns "a b".
- printf: Returns the format string according to a format specifier and returns the resulting string. printf("%s is %d years old.\n" "Eddie" 17) returns "Eddie is 17 years old.\n"
- println: Returns the format string using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended. println("Eddie" "is" 17 "years old." "Eddie" 17) returns "Eddie is 17 years old.\n"
- urlquery: Returns the escaped value of the textual representation of its arguments in a form suitable for embedding in a URL query. This function is unavailable in html/template, with a few exceptions.
Using built-in functions
You can use the functions in the managed resource declaration in your deployment package.
Example
This example adds a function to get the ID of the deployed resource to use during deployment.
When you add "{{resourceId `sampleDocName`}}" to your package, you are using the resourceId function. The double curly brackets indicate that the syntax inside the double curly brackets is a template expression. The deployment process resolves the syntax rather than treating it as a literal value.
The following JSON highlights the changes needed to add a resourceId function. In this example, the function gets the ID of the deployed SampleResource for deployment, and the value will vary based on the deployed resource's ID.
{
"$schema": "https://app.laserfiche.com/resourcemanagement/schemas/2022-01/deploymentTemplate.json",
"variables": [],
"resources": [
{
"type": "SampleApplication/SampleResource",
"apiVersion": 1,
"resourceName": "sample document SampleResource",
"declaration": {
"id": "c7692711-5cf6-4c91-8494-12d1545e9cfa",
"name": "sample document",
"content": "test sample resource content"
}
},
{
"type": "SampleApplication/SampleResource",
"apiVersion": 1,
"resourceName": "sample document 2 SampleNewResource",
"declaration": {
"id": "FDFE8338-702C-4F78-B57C-304B02841CF2",
"name": "document depends on sample document",
"content": "content is dependent on SampleResource \"{{resourceId `sample document SampleResource`}}\""
}
}
]
}
After using the functions in the deployment package, the content of SampleNewResource will be auto updated based on the SampleResource deployment.
Adding variables in a package
Variables can simplify deployment packages by letting you write a JSON fragment once and reuse it throughout the deployment package. Also by using a variable you don't have to keep track of unique resource names throughout your package.
Declaring a variable
Declaring a variable requires naming the variable, specifying the variable type, and setting the variable's value, similar to the following fragment.
{ ... "variables": [ { "name": "{variable-name}", "type": "{variable-type}", "value": {variable-value}, "label": "{variable-label}", "allowedValues": [{allowed-value-list}] } ], ... }
Naming a variable
When naming your variable, follow the rules below:
- A name must begin with a letter and can have any number of additional letters and numbers.
- A variable name cannot start with a number.
- A variable name cannot contain spaces.
- If a name consists of multiple words, each word after the first should be capitalized like this: wfResourceName, WfResourceName, etc.
- Variable names are case-sensitive (car, Car, and CAR are three different variables)
Specifying a variable type and assigning value
Currently only the "string" type is supported for variables. Variable values must be strings.
Describing a variable
Variable label shows what the variable means or what the variable is used for. It will be displayed in the user interface.
Adding allowed values (optional)
If a variable is required to be one of several values, the variable allowedValues can be used for listing all the available values.
Using variables
Similar to use functions, when you add {{ .variables.sampleDoc1 }} or {{ $.variables.sampleDoc1 }}, you are using the defined variable sampleDoc1. The double curly brackets indicate that the syntax inside the double curly brackets is a package expression. The deployment resolves the syntax rather than treating it as a literal value. Now variables can be used in the managed resource's declaration in the deployment package.
The following example highlights the changes needed to add variables to the previous package which uses variables in the resources' names.
{ "$schema": "https://app.laserfiche.com/resourcemanagement/schemas/2022-01/deploymentTemplate.json", "variables": [ { "name": "sampleDoc1Name", "type": "string", "value": "sample document", "label": "The name of the sample doc 1" }, { "name": "sampleDoc2Name", "type": "string", "value": "sample document 2 SampleNewResource", "label": "Description for sample 2.", "allowedValues": [ "sample document 2 SampleNewResource", "sample document 2 SampleNewResource2", "sample document 2 SampleNewResource3" ] } ], "resources": [ { "type": "SampleApplication/SampleResource", "apiVersion": 1, "resourceName": "Resource12", "declaration": { "id": "c7692711-5cf6-4c91-8494-12d1545e9cfa", "name": "{{ .variables.sampleDoc1Name}}", "content": "test sample resource content" } }, { "type": "SampleApplication/SampleNewResource", "apiVersion": 1, "resourceName": "Resource1234", "declaration": { "id": "FDFE8338-702C-4F78-B57C-304B02841CF2", "name": "{{ $.variables.sampleDoc2Name}}", "content": "test sample resource content is dependent on SampleResource \"{{resourceId `Resource12`}}\"" } } ] }
Notice that it includes two variables sampleDoc1Name and sampleDoc2Name. These variables are assigned with a string value. Note that the resource names are using the defined variables. The variables can also be used as function parameters. In this example, .variables.sampleDoc1Name is used as the argument of the function resourceId.
Advanced variable use
If you are familiar with Go, you can do a lot of advanced editing in the deployment package. In the managed resource declaration, you can define a variable with a value of a local variable that can be used in the current resource declaration only, e.g., {{$variablePipeline := `pipeline`}}.
For these local variables, you can only use the local variable in the managed resource declaration where you create the local variable. When deployment meets {{$variablePipeline}} in the current managed resource declaration, {{$variablePipeline}} is resolved as pipeline. The local variable can be updated with a new value in current managed resource declaration, e.g.,{{$variablePipeline = `pipeline2`}}. Then {{$variablePipeline}} will be resolved as the new value pipeline2 afterward. If you use the local variable in another managed resource declaration, you will not be able to deploy the package because of a syntax error from using an undefined variable.
Note: Exporting local variables is not supported in Laserfiche deployment package templates.
Adding linked resources in packages
Sometimes you want to use resources that exist in resource providers instead of creating a new resource and then adding it to a resource group. Linked Resource lets you reference property values of existing resources.
Declaring a linked resource
Declare a linked resource includes naming, specifying type and API version.
{ ... "linkedResources": [ { "resourceName": "LRName", "type": "PA/WorkFlow", "apiVersion": 1, "label": "Description of LRName" } ], ... }
Naming a linked resource
When creating a linked resource, its name cannot start or end with whitespace characters.
Specifying type and API version
Similar to specifying type and API version for resources. The only difference between is that the linked resource type must be a root resource type.
Describing a linked resource
Describing a linked resource is the same as describing a variable (see above).
Using linked resources
When you add {{ resourceId `LRName` }} ,you are using the resource ID of the defined linked resource LRName. The double curly brackets indicate that the syntax inside the double curly brackets is a template expression. Deployment resolves the syntax rather than treating it as a literal value. Now linked resources can only be used inside resource declarations in the deployment package.
The properties listed below can be referenced when using linked resources:
- resourceId
- resourceName
- resourceVersion
The following example highlights how to use linked resource property values in a package.
{ "$schema": "https://app.laserfiche.com/resourcemanagement/schemas/2022-01/deploymentTemplate.json", "linkedResources": [ { "resourceName": "Workflow0", "type": "PA/Workflow", "apiVersion": 1, "label": "Description of LRName" } ], "resources": [ { "type": "PA/BusinessProcess", "apiVersion": 1, "resourceName": "BP0", "declaration": { "id": "FDFE8338-702C-4F78-B57C-304B02841CF2", "name": "document depends on sample document", "referencedWfId": "{{ resourceId `Workflow0` }}", "referencedWfName": "{{ resourceName `Workflow0` }}", "referencedWfVersion": "{{ resourceVersion `Workflow0` }}" } } ] }
Adding comments in a package
To add clarity to a deployment package's JSON, you can add comments to describe any part of the package. Comments have no effect on how the package deploys.
{ "//schemaComment": "The schema provides data structure in the deployment template.", "$schema": "https://app.laserfiche.com/resourcemanagement/schemas/2022-01/deploymentTemplate.json", "//variableComment": [ "sampleDoc1Name is the name of sample 1." ], "variables": [ { "name": "sampleDoc1Name", "type": "string", "//exampleValue": "value1, value2, value3...", "value": "sample document SampleResource", "label": "Description for sample 1." } ], "linkedResources": [ { "//linkedResourceComment": "This linked resource is for...", "resourceName": "Workflow0", "type": "PA/Workflow", "apiVersion": 1, "label": "Description of LRName" } ], "resources": [ { "//resourceComment": "This resource is for...", "type": "SampleApplication/SampleResource", "apiVersion": 1, "resourceName": "{{ .variables.sampleDoc1Name}}", "declaration": { "//declarationComment": [ "Id is...", "Name is...", "Content is..." ], "id": "c7692711-5cf6-4c91-8494-12d1545e9cfa", "name": "sample document", "content": "test sample resource content" } } ] }