Skip to main content

Computation examples

View multiple examples of Workflow Computations

Everyone likes having examples to look at, so here's a bunch of them for you to examine!

We hope they aid your understanding and show you the kind of things that are possible with Workflow Computations.

General examples

Example 1 - Set an attribute to the value of a computed variable

In this example, the value of the MyNumber attribute is set to the computed mySumVariable. This can be done using a script in the parameter.

{
"signature": "5f04d06382cc0e00664ee9cd",
"parameters": [
{
"attributeCode": "attributes_streetLightsMyNumber_5f0451bc82cc0e00664ee570",
"value": {
"script": "return $mySumVariable",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "mySumVariable",
"value": {
"script": "return 3+5;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}

Alternatively, by referencing the variable directly in the parameter.

{
"signature": "5f04d06382cc0e00664ee9cd",
"parameters": [
{
"attributeCode": "attributes_streetLightsMyNumber_5f0451bc82cc0e00664ee570",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueVariableWebModel",
"variableName": "mySumVariable"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "mySumVariable",
"value": {
"script": "return 3+5;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 2 - Set an attribute to the sum of 2 other attributes

In this example, we take two existing attribute values (from the Example A and Example B) and perform a computation with them to set a third attribute (Example C).

{
"signature": "5f04d37982cc0e00664eea02",
"parameters": [
{
"attributeCode": "attributes_streetLightsExampleC_5f04d1a282cc0e00664ee9f8",
"value": {
"script": "return variableA + variableB;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "variableA",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_streetLightsExampleA_5f0451bc82cc0e00664ee570",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
"name": "variableB",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_streetLightsExampleB_5f0451de82cc0e00664ee575",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
}
]
}
Example 3 - Calculate the current asset value

In this example, we extract the values for three attributes on the current node and use them to calculate the current asset value based on linear depreciation. The three attributes we need are Installed Date, Installed Value and the Total Life of the asset in years.

The script uses the current (local) time to calculate the remaining life of the asset. It then uses the ratio of remaining life to total life to calculate the current remaining value.

{
"signature": "5f05922082cc0e00664eea80",
"parameters": [
{
"attributeCode": "attributes_streetLightsCurrentValue_5f05870582cc0e00664eea72",
"value": {
"script" : "var totalLifeHours = totalLifeYears * 8760;
var remainingLifeHours = totalLifeHours - (Local(Now) - installedDate).TotalHours;
return installedValue * remainingLifeHours / totalLifeHours;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "installedDate",
"value": {
"inputParent": 0,
"itemValue" : {
"attributeCode": "attributes_assetsInstalledDate",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
"name": "installedValue",
"value": {
"inputParent": 0,
"itemValue" : {
"attributeCode": "attributes_streetLightsInstalledValue_5f0586c982cc0e00664eea6d",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
"name": "totalLifeYears",
"value": {
"inputParent": 0,
"itemValue" : {
"attributeCode": "attributes_streetLightsTotalLife_5f05c7f2c3ca920067f1d6db",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
}
]
}
Example 4 - Count the number of tasks in a project

In this example, we count the number of tasks stored in a project and set an attribute on the project to this value. The numTasks variable gets the list of Item IDs stored in attributes_projectsTasks. We can count these ids by using the Elements(numTasks) function followed by the LINQ Sum() function.

{
"signature": "5f06e25676ea240066bd2719",
"parameters": [
{
"attributeCode": "attributes_projectsTaskPoints_5f06170ac3ca920067f1d829",
"value": {
"script": "return Elements(numTasks).Sum();",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "numTasks",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_projectsTasks",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
}
]
}
Example 5 - Sum the number of points on each job in a project

This example builds on the previous example. We can also sum a Number attribute (attributes_basicStreetLightingJobsPoints in this example) on each job item. Note that the job items are accessed from the output of another node (a Relation action), which finds jobs linked to the project. A similar type of computation could be used to go from Jobs to Job Work Items.

{
"signature": "5f06e25676ea240066bd2719",
"parameters": [
{
"attributeCode": "attributes_projectsTaskPoints_5f06170ac3ca920067f1d829",
"value": {
"script": "return Elements(taskPoints).Sum();",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "taskPoints",
"value": {
"outputAction": "5f05f8afc3ca920067f1d80b",
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_basicStreetLightingJobsPoints_5f05fd84c3ca920067f1d819"
},
"discriminator": "WorkflowSyntaxNodeOutputWebModel"
}
}
],
"actionDesignCode": "designs_workflowEditItemAction"
}
Example 6 - Calculate Tree Crown Spread

This example demonstrates how to calculate the crown spread of a tree. It requires a central point for the tree and spread values for the four compass directions (in metres). Using Bézier Curves, a polygon is computed and then set as the value of attributes_treesSpreadGeometry.

alt text
{
"parameters": [
{
"attributeCode": "attributes_treesSpreadGeometry",
"value": {
"script": "return polygon_WGS84;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Geometry attribute from current node input (tree point)
"name": "geometry_WGS84",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsGeometry"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets spread north attribute value (m)
"name": "spread_north",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_treesSpreadNorth"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets spread west attribute value (m)
"name": "spread_west",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_treesSpreadWest"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets spread south attribute value (m)
"name": "spread_south",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_treesSpreadSouth"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets spread east attribute value (m)
"name": "spread_east",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_treesSpreadEast"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
// convert geometry to British National Grid
"name": "geometry_BNG",
"value": {
"script": "var geometry_BNG = GeometryMath.ProjectFromAlloyCrs(geometry_WGS84,\"+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs\");return geometry_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//gets X coordinate of the tree
"name": "tree_x_BNG",
"value": {
"script": "var tree_x_BNG=double.Parse(Json(geometry_BNG)[\"coordinates\"][0].ToString()); return tree_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//gets Y coordinate of the tree
"name": "tree_y_BNG",
"value": {
"script": "var tree_y_BNG=double.Parse(Json(geometry_BNG)[\"coordinates\"][1].ToString()); return tree_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes X coordinate of north spread
"name": "spread_north_x_BNG",
"value": {
"script": "return tree_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes Y coordinate of north spread
"name": "spread_north_y_BNG",
"value": {
"script": "var spread_north_y_BNG=tree_y_BNG+spread_north; return spread_north_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes X coordinate of east spread
"name": "spread_east_x_BNG",
"value": {
"script": "var spread_east_x_BNG=tree_x_BNG+spread_east; return spread_east_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes Y coordinate of east spread
"name": "spread_east_y_BNG",
"value": {
"script": "return tree_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes X coordinate of south spread
"name": "spread_south_x_BNG",
"value": {
"script": "return tree_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes Y coordinate of south spread
"name": "spread_south_y_BNG",
"value": {
"script": "var spread_south_y_BNG=tree_y_BNG-spread_south; return spread_south_y_BNG;;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes X coordinate of west spread
"name": "spread_west_x_BNG",
"value": {
"script": "var spread_west_x_BNG=tree_x_BNG-spread_west; return spread_west_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes Y coordinate of east spread
"name": "spread_west_y_BNG",
"value": {
"script": "return tree_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
//Computes XY coordinates of significant points of the 4 curves that connect the cardinal points
//uses Bézier formula to get points of the curve given a start, end and control point
{
"name": "spread_ne_25_x_BNG",
"value": {
"script": "var t=0.25;var spread_ne_25_x_BNG=(1-t)*(1-t)*spread_north_x_BNG.Value+2*(1-t)*t*spread_east_x_BNG.Value+t*t*spread_east_x_BNG.Value; return spread_ne_25_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_ne_25_y_BNG",
"value": {
"script": "var t=0.25;var spread_ne_25_y_BNG=(1-t)*(1-t)*spread_north_y_BNG.Value+2*(1-t)*t*spread_north_y_BNG.Value+t*t*spread_east_y_BNG.Value; return spread_ne_25_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_ne_50_x_BNG",
"value": {
"script": "var t=0.5;var spread_ne_50_x_BNG=(1-t)*(1-t)*spread_north_x_BNG.Value+2*(1-t)*t*spread_east_x_BNG.Value+t*t*spread_east_x_BNG.Value; return spread_ne_50_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_ne_50_y_BNG",
"value": {
"script": "var t=0.5;var spread_ne_50_y_BNG=(1-t)*(1-t)*spread_north_y_BNG.Value+2*(1-t)*t*spread_north_y_BNG.Value+t*t*spread_east_y_BNG.Value; return spread_ne_50_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_ne_75_x_BNG",
"value": {
"script": "var t=0.75;var spread_ne_75_x_BNG=(1-t)*(1-t)*spread_north_x_BNG.Value+2*(1-t)*t*spread_east_x_BNG.Value+t*t*spread_east_x_BNG.Value; return spread_ne_75_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_ne_75_y_BNG",
"value": {
"script": "var t=0.75;var spread_ne_75_y_BNG=(1-t)*(1-t)*spread_north_y_BNG.Value+2*(1-t)*t*spread_north_y_BNG.Value+t*t*spread_east_y_BNG.Value; return spread_ne_75_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_se_25_x_BNG",
"value": {
"script": "var t=0.25;var spread_se_25_x_BNG=(1-t)*(1-t)*spread_east_x_BNG.Value+2*(1-t)*t*spread_east_x_BNG.Value+t*t*spread_south_x_BNG.Value; return spread_se_25_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_se_25_y_BNG",
"value": {
"script": "var t=0.25;var spread_se_25_y_BNG=(1-t)*(1-t)*spread_east_y_BNG.Value+2*(1-t)*t*spread_south_y_BNG.Value+t*t*spread_south_y_BNG.Value; return spread_se_25_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_se_50_x_BNG",
"value": {
"script": "var t=0.5;var spread_se_50_x_BNG=(1-t)*(1-t)*spread_east_x_BNG.Value+2*(1-t)*t*spread_east_x_BNG.Value+t*t*spread_south_x_BNG.Value; return spread_se_50_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_se_50_y_BNG",
"value": {
"script": "var t=0.5;var spread_se_50_y_BNG=(1-t)*(1-t)*spread_east_y_BNG.Value+2*(1-t)*t*spread_south_y_BNG.Value+t*t*spread_south_y_BNG.Value; return spread_se_50_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_se_75_x_BNG",
"value": {
"script": "var t=0.75;var spread_se_75_x_BNG=(1-t)*(1-t)*spread_east_x_BNG.Value+2*(1-t)*t*spread_east_x_BNG.Value+t*t*spread_south_x_BNG.Value; return spread_se_75_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_se_75_y_BNG",
"value": {
"script": "var t=0.75;var spread_se_75_y_BNG=(1-t)*(1-t)*spread_east_y_BNG.Value+2*(1-t)*t*spread_south_y_BNG.Value+t*t*spread_south_y_BNG.Value; return spread_se_75_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_sw_25_x_BNG",
"value": {
"script": "var t=0.25;var spread_sw_25_x_BNG=(1-t)*(1-t)*spread_south_x_BNG.Value+2*(1-t)*t*spread_west_x_BNG.Value+t*t*spread_west_x_BNG.Value; return spread_sw_25_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_sw_25_y_BNG",
"value": {
"script": "var t=0.25;var spread_sw_25_y_BNG=(1-t)*(1-t)*spread_south_y_BNG.Value+2*(1-t)*t*spread_south_y_BNG.Value+t*t*spread_west_y_BNG.Value; return spread_sw_25_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_sw_50_x_BNG",
"value": {
"script": "var t=0.5;var spread_sw_50_x_BNG=(1-t)*(1-t)*spread_south_x_BNG.Value+2*(1-t)*t*spread_west_x_BNG.Value+t*t*spread_west_x_BNG.Value; return spread_sw_50_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_sw_50_y_BNG",
"value": {
"script": "var t=0.5;var spread_sw_50_y_BNG=(1-t)*(1-t)*spread_south_y_BNG.Value+2*(1-t)*t*spread_south_y_BNG.Value+t*t*spread_west_y_BNG.Value; return spread_sw_50_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_sw_75_x_BNG",
"value": {
"script": "var t=0.75;var spread_sw_75_x_BNG=(1-t)*(1-t)*spread_south_x_BNG.Value+2*(1-t)*t*spread_west_x_BNG.Value+t*t*spread_west_x_BNG.Value; return spread_sw_75_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_sw_75_y_BNG",
"value": {
"script": "var t=0.75;var spread_sw_75_y_BNG=(1-t)*(1-t)*spread_south_y_BNG.Value+2*(1-t)*t*spread_south_y_BNG.Value+t*t*spread_west_y_BNG.Value; return spread_sw_75_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_nw_25_x_BNG",
"value": {
"script": "var t=0.25;var spread_nw_25_x_BNG=(1-t)*(1-t)*spread_west_x_BNG.Value+2*(1-t)*t*spread_west_x_BNG.Value+t*t*spread_north_x_BNG.Value; return spread_nw_25_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_nw_25_y_BNG",
"value": {
"script": "var t=0.25;var spread_nw_25_y_BNG=(1-t)*(1-t)*spread_west_y_BNG.Value+2*(1-t)*t*spread_north_y_BNG.Value+t*t*spread_north_y_BNG.Value; return spread_nw_25_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_nw_50_x_BNG",
"value": {
"script": "var t=0.5;var spread_nw_50_x_BNG=(1-t)*(1-t)*spread_west_x_BNG.Value+2*(1-t)*t*spread_west_x_BNG.Value+t*t*spread_north_x_BNG.Value; return spread_nw_50_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_nw_50_y_BNG",
"value": {
"script": "var t=0.5;var spread_nw_50_y_BNG=(1-t)*(1-t)*spread_west_y_BNG.Value+2*(1-t)*t*spread_north_y_BNG.Value+t*t*spread_north_y_BNG.Value; return spread_nw_50_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_nw_75_x_BNG",
"value": {
"script": "var t=0.75;var spread_nw_75_x_BNG=(1-t)*(1-t)*spread_west_x_BNG.Value+2*(1-t)*t*spread_west_x_BNG.Value+t*t*spread_north_x_BNG.Value; return spread_nw_75_x_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "spread_nw_75_y_BNG",
"value": {
"script": "var t=0.75;var spread_nw_75_y_BNG=(1-t)*(1-t)*spread_west_y_BNG.Value+2*(1-t)*t*spread_north_y_BNG.Value+t*t*spread_north_y_BNG.Value; return spread_nw_75_y_BNG;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes a polygon geometry by joining together all the XY coordinates
//Polygon -> array of LineStrings -> array of Positions
"name": "polygon_WGS84",
"value": {
"script": "var polygon_BNG=Polygon(LineString(Position(spread_north_y_BNG.Value, spread_north_x_BNG.Value),Position(spread_ne_25_y_BNG.Value, spread_ne_25_x_BNG.Value),Position(spread_ne_50_y_BNG.Value, spread_ne_50_x_BNG.Value),Position(spread_ne_75_y_BNG.Value, spread_ne_75_x_BNG.Value),Position(spread_east_y_BNG.Value, spread_east_x_BNG.Value),Position(spread_se_25_y_BNG.Value, spread_se_25_x_BNG.Value),Position(spread_se_50_y_BNG.Value, spread_se_50_x_BNG.Value),Position(spread_se_75_y_BNG.Value, spread_se_75_x_BNG.Value),Position(spread_south_y_BNG.Value, spread_south_x_BNG.Value),Position(spread_sw_25_y_BNG.Value, spread_sw_25_x_BNG.Value),Position(spread_sw_50_y_BNG.Value, spread_sw_50_x_BNG.Value),Position(spread_sw_75_y_BNG.Value, spread_sw_75_x_BNG.Value),Position(spread_west_y_BNG.Value, spread_west_x_BNG.Value),Position(spread_nw_25_y_BNG.Value, spread_nw_25_x_BNG.Value),Position(spread_nw_50_y_BNG.Value, spread_nw_50_x_BNG.Value),Position(spread_nw_75_y_BNG.Value, spread_nw_75_x_BNG.Value),Position(spread_north_y_BNG.Value, spread_north_x_BNG.Value)));var polygon_WGS84=GeometryMath.ProjectToAlloyCrs(polygon_BNG,\"+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs\");return polygon_WGS84;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 7 - Customise SMS/email message text

This workflow intercepts a Message action and changes the text included in the message.

{
"parameters": [
{
//SMS message type id
"attribute": {
"attributeCode": "attributes_workflowMessageActionMessageType",
"value": ["5c66bcd44b4d4259071069df"]
},
"discriminator": "WorkflowConstantItemAttributeWebModel"
},
{
//edits message text using template model. Combine static text with dynamic text from the input item attributes
"attributeCode": "attributes_workflowMessageActionMessageText",
"value": {
"template": "A new defect has been reported. Id: & $itemId &. Title: & $title &. Subtitle: & $subtitle",
"discriminator": "WorkflowSyntaxNodeTemplateWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
},
{
"attribute": {
"attributeCode": "attributes_workflowMessageActionRecipientName",
"value": "Arnau"
},
"discriminator": "WorkflowConstantItemAttributeWebModel"
},
{
"attribute": {
"attributeCode": "attributes_workflowMessageActionMobileNumber",
"value": "+447436425222"
},
"discriminator": "WorkflowConstantItemAttributeWebModel"
}
],
"variables": [
{
//gets title from current node input
"name": "title",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsTitle"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets subtitle from current node input "name": "subtitle",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsSubtitle"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets item ID from current node input
"name": "itemId",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueItemPropertyWebModel",
"property": "ItemId"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
}
]
}
Example 8 - Generate a random number

This example demonstrates how to use the Random() helper function to generate a random number between 100 and 200. This is perfect for situations where a random subset of items is required.

{
"signature": "5f0842b78a99b30066d0ff4b",
"parameters": [
{
"attributeCode": "attributes_streetLightsA_5f0451bc82cc0e00664ee570",
"value": {
"script": "return random;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "random",
"value": {
"script": "var rnd = new Random();return rnd.Next(100,200);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}

DateTime examples

In Alloy, all DateTime values are stored as UTC±00:00. When a DateTime value is viewed or searched for, it's converted on the fly to your organisation's local time zone. When a DateTime value is saved, it's automatically converted to UTC.

Therefore, when writing a workflow computation script, use the Local() function to wrap any DateTime values. This is recommended even if you're located in a UTC±00:00 timezone, as daylight saving time may affect your computed values!

Caution

It isn't possible to save a localised DateTime value as a parameter or variable within a workflow computation.

Example 1 - Convert a DateTime attribute to a Date attribute

This example takes the value of a DateTime attribute, discards the Time element, then stores the Date in a Date attribute.

{
"parameters": [
{
//saves date into the specified attribute
"attributeCode": "attributes_jobStartDate",
"value": {
"script": "return startDate;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Start Time datetime attribute from current node input
"name": "startDateTime",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_tasksStartTime"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//convert datetime to date
"name": "startDate",
"value": {
"script": "var startDate = Date(startDateTime); return startDate;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 2 - Check if a DateTime attribute represents a weekday

This example takes the value of the Start Time attribute on a task item, checks if it occurs during the week or the weekend, and then sets the value the Day Type attribute as Weekday or Weekend.

{
"parameters": [
{
//saves day type text into the specified attribute
"attributeCode": "attributes_jobDayType",
"value": {
"script": "return dayType;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Start Time datetime attribute from current node input
"name": "startDateTime",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_tasksStartTime"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//converts datetime to DayOfWeek and checks whether it is a Saturday or Sunday or not.
//if True returns "Weekend", if False returns "Weekday"
"name": "dayType",
"value": {
"script": "var dayType= \"Weekday\"; var day = Local(startDateTime).Value.DayOfWeek; if((day == DayOfWeek.Saturday) || (day == DayOfWeek.Sunday)){ dayType=\"Weekend\"; } return dayType;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 3 - Compute the total duration of a task

This example computes the duration between two DateTime attributes. It then saves the number of hours into the Total Hours attribute, the minutes into the Total Minutes attribute, and the seconds into the Total Seconds attribute.

{
"parameters": [
{
//saves task duration in hours into the specified attribute
"attributeCode": "attributes_jobTotalHours",
"value": {
"script": "return totalHours;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
},
{
//saves task duration in minutes into the specified attribute
"attributeCode": "attributes_jobTotalMinutes",
"value": {
"script": "return totalMinutes;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
},
{
//saves task duration in seconds into the specified attribute
"attributeCode": "attributes_jobTotalSeconds",
"value": {
"script": "return totalSeconds;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Start Time datetime attribute from current node input
"name": "startDateTime",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_tasksStartTime"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets Completion Time datetime attribute from current node input
"name": "completionDateTime",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_tasksCompletionTime"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//computes task duration and converts it to hours
"name": "totalHours",
"value": {
"script": "var duration = completionDateTime - startDateTime; return duration.Value.TotalHours;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes task duration and converts it to minutes
"name": "totalMinutes",
"value": {
"script": "var duration = completionDateTime - startDateTime; return duration.Value.TotalMinutes;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes task duration and converts it to seconds
"name": "totalSeconds",
"value": {
"script": "var duration = completionDateTime - startDateTime; return duration.Value.TotalSeconds;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 4 - Compute the days remaining for a task

This example computes the number of days from now until the Target Time attribute of a task.

It does this by subtracting the target time from the current local time. Both values are rounded down to the nearest day, so that the computed value is an integer. If the target time has passed, the value will be negative.

{
"parameters": [
{
//saves days remaining into the specified attribute
"attributeCode": "attributes_tasksDaysRemaining_664799edf3061a7fb0daf9c1",
"value": {
"script": "return daysToTarget;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Target Time datetime attribute from current node input
"name": "targetTime",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_tasksTargetTime",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//computes the days between the target time and now
"name": "daysToTarget",
"value": {
"discriminator": "WorkflowSyntaxNodeScriptWebModel",
"script": "var localTarget = DateTimeMath.Floor(Local(targetTime.Value), DateTimeMath.Day); var localNow = DateTimeMath.Floor(Local(Now), DateTimeMath.Day); return (localTarget.Value - localNow.Value).Days;"
}
}
]
}

Geographic examples

In Alloy, all geometry is stored using the WGS84 Lat/Lng (EPSG:4326) coordinate system. When geometry is viewed or searched for, it's converted on the fly to the coordinate system used by the current basemap. When geometry is saved, it's automatically converted to WGS84 Lat/Lng.

Therefore, when writing a workflow computation, consider whether you need to convert a geometry value before using it.

Example 1: Convert coordinates to another system (Universal Transverse Mercator)

In this example, the item's geometry is converted to the WGS 84 / UTM zone 30N (EPSG:32630) coordinate system using a Proj4 projection string. This UTM zone includes the UK. The transformed coordinates are then converted to JSON and saved to the UTM attribute.

For UTM zones containing other countries, substitute +zone=30 +north with the relevant values, e.g. New Zealand would be +zone=59 +south.

{
"signature": "5f0842b78a99b30066d0ff4b",
"parameters": [
{
"attributeCode": "attributes_streetLightsUTM_5f52693372b4d50065a614d8",
"value": {
"script" : "var geometryUTM = GeometryMath.ProjectFromAlloyCrs(geometryWGS84,\"+proj=utm +zone=30 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs\");
return GeometryMath.Length(geometryUTM);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "geometryWGS84",
"value": {
"inputParent": 0,
"itemValue" : {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsGeometry"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
}
]
}
Example 2: Convert coordinates to another system (British National Grid)

In this example, the item's geometry is converted to the British National Grid (EPSG:27700) coordinate system using a Proj4 projection string. The transformed coordinates are then converted to JSON and saved to the BNG attribute.

{
"signature": "5f0842b78a99b30066d0ff4b",
"parameters": [
{
"attributeCode": "attributes_streetLightsBNG_5f52693372b4d50065a614d8",
"value": {
"script" : "var geometryBNG = GeometryMath.ProjectFromAlloyCrs(geometryWGS84,\"+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs\");
return Json(geometryBNG);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
"name": "geometryWGS84",
"value": {
"inputParent": 0,
"itemValue" : {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsGeometry"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
}
]
}
Example 3 - Compute the area of an item's geometry

This example gets the value of the Geometry attribute on the input item of the current node. First, the geometry coordinates are converted from WGS84 Lat/Lng (EPSG:4326) to WGS 84 / UTM zone 30N (EPSG:32630). The area is calculated in square metres and then saved to the Asset Area attribute.

{
"parameters": [
{
//saves area (sqm) to the specified attribute
"attributeCode": "attributes_polygonAssetArea",
"value": {
"script": "return area;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Geometry attribute from current node input
"name": "geometryWGS84",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsGeometry"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//reprojects geometry to UTM Zone 30 which uses metres
"name": "geometryUTM",
"value": {
"script": "var geometryUTM = GeometryMath.ProjectFromAlloyCrs(geometryWGS84,\"+proj=utm +zone=30 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs\");
return GeometryMath.Length(geometryUTM);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes area
"name": "area",
"value": {
"script": "return GeometryMath.Area(geometryUTM);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 4 - Compute the length of an item's geometry

Similar to the previous example, this example gets the value of the Geometry attribute on the input item of the current node. First, the geometry coordinates are converted from WGS84 Lat/Lng (EPSG:4326) to WGS 84 / UTM zone 30N (EPSG:32630). The length is calculated in metres and then saved to the Asset Length attribute.

{
"parameters": [
{
//saves length (m) into the specified attribute
"attributeCode": "attributes_linearAssetLength",
"value": {
"script": "return length;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Geometry attribute from current node input
"name": "geometryWGS84",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsGeometry"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//reprojects geometry to UTM Zone 30 which uses metres
"name": "geometryUTM",
"value": {
"script": "var geometryUTM = GeometryMath.ProjectFromAlloyCrs(geometryWGS84,\"+proj=utm +zone=30 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs\");
return GeometryMath.Length(geometryUTM);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//computes length
"name": "length",
"value": {
"script": "return GeometryMath.Length(geometryUTM);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 5 - Compute the area and volume of a pot hole

A pot hole inspection typically involves recording its length, width and depth. This example uses these measurements to compute the area and volume of the pothole. It then saves the computed values to the WFC Area and WFC Volume attributes.

{
"parameters": [
{
//saves area (length*width) into the specified attribute
"attributeCode": "attributes_potHoleWFCArea",
"value": {
"script": "return length*width;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
},
{
//saves volume (length*width*depth) into the specified attribute
"attributeCode": "attributes_potHoleWFCVolume",
"value": {
"script": "return length*width*depth;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Length number attribute from current node input
"name": "length",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_potHoleWFCLength",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets Width number attribute from current node input
"name": "width",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_potHoleWFCWidth",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//gets Depth number attribute from current node input
"name": "depth",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_potHoleWFCDepth",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
}
]
}

The Depth and Volume values would be combined and then assigned to their respective attributes.

Example 6 - Compute the centroid point of a polygon

This example demonstrates how to compute the centroid point of a geometry and save the computed longitude and latitude into two attributes.

{
"parameters": [
{
//saves centroid latitude into the specified attribute
"attributeCode": "attributes_jobCentroidLatitude",
"value": {
"script": "return latitude;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
},
{
//saves centroid longitude into the specified attribute
"attributeCode": "attributes_jobTestCentroidLongitude",
"value": {
"script": "return longitude;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Geometry attribute from current node input
"name": "geometryWGS84",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsGeometry"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//computes centroid point
"name": "centroidGeometry",
"value": {
"script": "return GeometryMath.Centroid(geometryWGS84);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//gets latitude from centroid point
"name": "latitude",
"value": {
"script": "var centroidPoint = centroidGeometry as GeoJSON.Net.Geometry.Point; var latitude = centroidPoint.Coordinates.Latitude;return latitude;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//gets longitude from centroid point
"name": "longitude",
"value": {
"script": "var centroidPoint = centroidGeometry as GeoJSON.Net.Geometry.Point; var longitude = centroidPoint.Coordinates.Longitude;return longitude;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 7 - Compute the extent (bounding box) of an item's geometry

This example computes the extent of an item's geometry and stores the SE and NW corners of its bounding box into two attributes.

{
"parameters": [
{
//saves SW "Longitude,Latitude" pair into the specified text attribute
"attributeCode": "attributes_assetSWExtent",
"value": {
"script": "return WGS84_BBOX_West+\",\"+WGS84_BBOX_South;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
},
{
//saves NE "Longitude,Latitude" pair into the specified text attribute
"attributeCode": "attributes_assetNEExtent",
"value": {
"script": "return WGS84_BBOX_East+\",\"+WGS84_BBOX_North;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//gets Geometry attribute from current node input
"name": "geometryWGS84",
"value": {
"inputParent": 0,
"itemValue": {
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel",
"attributeCode": "attributes_itemsGeometry"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//computes centroid point
//if input geometry is a point -> centroid is a point geometry
//else centroid is a polygon geometry
"name": "geometryWGS84_BBOX",
"value": {
"script": "return GeometryMath.BoundingBox(geometryWGS84);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//checks whether input is a point or a polygon and gets south latitude
"name": "WGS84_BBOX_South",
"value": {
"script": "var WGS84_BBOX_South=\"\"; var jsonGeom=Json(geometryWGS84_BBOX);var geometryTypeString = jsonGeom[\"type\"].ToString();if(geometryTypeString==\"Point\"){WGS84_BBOX_South=jsonGeom[\"coordinates\"][1].ToString();}else{WGS84_BBOX_South=jsonGeom[\"coordinates\"][0][0][1].ToString();}return WGS84_BBOX_South;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//checks whether input is a point or a polygon and gets west longitude
"name": "WGS84_BBOX_West",
"value": {
"script": "var WGS84_BBOX_West=\"\"; var jsonGeom=Json(geometryWGS84_BBOX);var geometryTypeString = jsonGeom[\"type\"].ToString();if(geometryTypeString==\"Point\"){WGS84_BBOX_West=jsonGeom[\"coordinates\"][0].ToString();}else{WGS84_BBOX_West=jsonGeom[\"coordinates\"][0][0][0].ToString();}return WGS84_BBOX_West;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//checks whether input is a point or a polygon and gets north latitude
"name": "WGS84_BBOX_North",
"value": {
"script": "var WGS84_BBOX_North=\"\"; var jsonGeom=Json(geometryWGS84_BBOX);var geometryTypeString = jsonGeom[\"type\"].ToString();if(geometryTypeString==\"Point\"){WGS84_BBOX_North=jsonGeom[\"coordinates\"][1].ToString();}else{WGS84_BBOX_North=jsonGeom[\"coordinates\"][0][2][1].ToString();}return WGS84_BBOX_North;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//checks whether input is a point or a polygon and gets east longitude
"name": "WGS84_BBOX_East",
"value": {
"script": "var WGS84_BBOX_East=\"\"; var jsonGeom=Json(geometryWGS84_BBOX);var geometryTypeString = jsonGeom[\"type\"].ToString();if(geometryTypeString==\"Point\"){WGS84_BBOX_East=jsonGeom[\"coordinates\"][0].ToString();}else{WGS84_BBOX_East=jsonGeom[\"coordinates\"][0][2][0].ToString();}return WGS84_BBOX_East;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 8 - Compute circular geometry from a point

This example demonstrates how to generate a circular polygon centred on a given point. This can be used to determine the Root Protection Area of a tree.

{
"parameters": [
{
//update the geometry with the new computed geometry
"attributeCode": "attributes_itemsGeometry",
"value": {
"script": "return buffered_geometry_WGS84;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
}
],
"variables": [
{
//get the current asset geometry (using a Tree asset in this example - point geometry) - adjust the "inputParent" as necessary
"name": "geometry_WGS84",
"value": {
"inputParent": 2,
"itemValue": {
"attributeCode": "attributes_itemsGeometry",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//convert the geometry to UTM Zone 30 so that it can be manipulated
"name": "geometry_UTM",
"value": {
"script": "var geometryUTM = GeometryMath.ProjectFromAlloyCrs(geometryWGS84,\"+proj=utm +zone=30 +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs\");
return GeometryMath.Length(geometryUTM);",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//get or set the distance from the point that you want to buffer from - in this case the distance from the tree
"name": "tree_radius",
"value": {
"inputParent": 2,
"itemValue": {
"attributeCode": "attributes_treesRootProtectionAreaRadius",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
//calculate the new polygon using GeometryMath.Buffer
"name": "buffered_geometry_UTM",
"value": {
"script": "var buffered_geometry_UTM = GeometryMath.Buffer(tree_radius.Value,geometry_UTM) ;return buffered_geometry_UTM;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
//convert the UTM geometry back to WGS84 so that it can be saved back to alloy
"name": "buffered_geometry_WGS84",
"value": {
"script": "var buffered_geometry_WGS84 = GeometryMath.ProjectToAlloyCrs(buffered_geometry_UTM,\"+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs\"); return buffered_geometry_WGS84;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
}
Example 9 - Fetch items that intersect with an item's geometry

This example identifies where point geometry (in this case, of a newly created job), intersects with a polygon. This is used to identify which ward the job has been created in and links the two.

The example programmatically creates an AQS query to be used within a Query node, taking the job's geometry and inserting it as text into the AQS query at the relevant node.

{
"parameters": [
{
"attributeCode": "attributes_workflowQueryActionsAqsQuery",
"value": {
"script": "return Aqs(aqs_json);",
"returnOptions": {
"dodiCode": "designs_ward",
"discriminator": "DodiAttributeOptionsAqsWebModel"
},
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
},
"discriminator": "WorkflowComputedItemAttributeWebModel"
},
{
"discriminator": "WorkflowConstantItemAttributeWebModel",
"attribute": {
"attributeCode": "attributes_workflowQueryActionsSingleInstance",
"value": false
}
}
],
"variables": [
{
"name": "geometry",
"value": {
"inputParent": 0,
"itemValue": {
"attributeCode": "attributes_itemsGeometry",
"discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
},
"discriminator": "WorkflowSyntaxNodeInputWebModel"
}
},
{
"name": "geometry_string",
"value": {
"script": "var geometry_string = Json(geometry).ToString(); return geometry_string;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "aqs_string",
"value": {
"script": "string json = @\"{'type': 'Query','properties': {'attributes': [],'collectionCode': ['Live'],'dodiCode': 'designs_ward'},'children': [{'type': 'GeomIntersects','children': [{'type': 'Attribute','properties': {'attributeCode': 'attributes_itemsGeometry'}},{'type': 'Geometry','properties': {'value':\"+ geometry_string+\"}}]}]}\"; return json.Replace(\"'\",\"\\\"\");",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
},
{
"name": "aqs_json",
"value": {
"script": "var o = JToken.Parse(aqs_string); return o;",
"discriminator": "WorkflowSyntaxNodeScriptWebModel"
}
}
]
``}