Skip to content

Commit 22364f1

Browse files
authored
Merge pull request #112973 from tfitzmac/0427functions3
added coalesce
2 parents 364da30 + d8541bb commit 22364f1

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

articles/azure-resource-manager/templates/template-functions-comparison.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,88 @@ ms.date: 04/27/2020
88

99
Resource Manager provides several functions for making comparisons in your Azure Resource Manager (ARM) templates.
1010

11+
* [coalesce](#coalesce)
1112
* [equals](#equals)
1213
* [greater](#greater)
1314
* [greaterOrEquals](#greaterorequals)
1415
* [less](#less)
1516
* [lessOrEquals](#lessorequals)
1617

18+
## coalesce
19+
20+
`coalesce(arg1, arg2, arg3, ...)`
21+
22+
Returns first non-null value from the parameters. Empty strings, empty arrays, and empty objects are not null.
23+
24+
### Parameters
25+
26+
| Parameter | Required | Type | Description |
27+
|:--- |:--- |:--- |:--- |
28+
| arg1 |Yes |int, string, array, or object |The first value to test for null. |
29+
| additional args |No |int, string, array, or object |Additional values to test for null. |
30+
31+
### Return value
32+
33+
The value of the first non-null parameters, which can be a string, int, array, or object. Null if all parameters are null.
34+
35+
### Example
36+
37+
The following [example template](https://github.com/Azure/azure-docs-json-samples/blob/master/azure-resource-manager/functions/coalesce.json) shows the output from different uses of coalesce.
38+
39+
```json
40+
{
41+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
42+
"contentVersion": "1.0.0.0",
43+
"parameters": {
44+
"objectToTest": {
45+
"type": "object",
46+
"defaultValue": {
47+
"null1": null,
48+
"null2": null,
49+
"string": "default",
50+
"int": 1,
51+
"object": {"first": "default"},
52+
"array": [1]
53+
}
54+
}
55+
},
56+
"resources": [
57+
],
58+
"outputs": {
59+
"stringOutput": {
60+
"type": "string",
61+
"value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').string)]"
62+
},
63+
"intOutput": {
64+
"type": "int",
65+
"value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').int)]"
66+
},
67+
"objectOutput": {
68+
"type": "object",
69+
"value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').object)]"
70+
},
71+
"arrayOutput": {
72+
"type": "array",
73+
"value": "[coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2, parameters('objectToTest').array)]"
74+
},
75+
"emptyOutput": {
76+
"type": "bool",
77+
"value": "[empty(coalesce(parameters('objectToTest').null1, parameters('objectToTest').null2))]"
78+
}
79+
}
80+
}
81+
```
82+
83+
The output from the preceding example with the default values is:
84+
85+
| Name | Type | Value |
86+
| ---- | ---- | ----- |
87+
| stringOutput | String | default |
88+
| intOutput | Int | 1 |
89+
| objectOutput | Object | {"first": "default"} |
90+
| arrayOutput | Array | [1] |
91+
| emptyOutput | Bool | True |
92+
1793
## equals
1894

1995
`equals(arg1, arg2)`

0 commit comments

Comments
 (0)