You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please review the following PR and provide a detailed review of the changes according the ./CONTRIBUTING.md provide results in markdown format.
75
+
Please review the following PR and provide a detailed review of the changes according the ./CONTRIBUTING.md provide results in markdown format. Ignore all image files.
Copy file name to clipboardExpand all lines: docs/actions-and-automations/setup-backend/create-update-entity/create-update-entity.md
+108-2Lines changed: 108 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,6 @@
1
+
import Tabs from "@theme/Tabs"
2
+
import TabItem from "@theme/TabItem"
3
+
1
4
# Create/update entity
2
5
3
6
In some cases, we don't want to run complex logic via a workflow or pipeline, but rather want our backend to simply create or update an entity in our software catalog.
@@ -33,15 +36,15 @@ To use this backend type, you will need to define the following fields:
33
36
| `team` | The team/s this entity will belong to. |
34
37
| `icon` | The icon of the entity. |
35
38
| `properties` | The properties of the entity, in `"key":"value"` pairs where the key is the property's identifier, and the value is its value. |
36
-
| `relations` | The relations of the entity, in `"key":"value"` pairs where the key is the relation's identifier, and the value is the related entity's identifier. |
39
+
| `relations` | The relations of the entity, in `"key":"value"` pairs where the key is the relation's identifier, and the value is the related entity's identifier (for single relations) or an array of identifiers (for "many" relations). |
37
40
38
41
### Use jq to map the entity
39
42
40
43
All fields in the `mapping` object can be mapped using `jq` expressions, by wrapping the value in double curly braces `{{ }}`.
41
44
42
45
For example, say we want to assign the initiator of the action to a new entity when it is created, we can take his email from the action run object and assign it to a property named `assignee`:
43
46
44
-
```json
47
+
```json showLineNumbers
45
48
{
46
49
"identifier": "someTaskEntity",
47
50
"title": "Some Task",
@@ -55,3 +58,106 @@ For example, say we want to assign the initiator of the action to a new entity w
55
58
:::tip Test your mapping
56
59
You can use the `Test JQ` button in the bottom-left corner to test your mapping against the action's schema.
57
60
:::
61
+
62
+
## Map entity relations
63
+
64
+
When creating or updating entities, you often need to establish relations with other entities. The mapping approach depends on whether you're dealing with single or multiple entity inputs.
For a single entity relation, map the entity identifier directly:
76
+
77
+
```json showLineNumbers
78
+
{
79
+
"identifier": "myServiceEntity",
80
+
"title": "My Service",
81
+
"properties": {},
82
+
"relations": {
83
+
"domain": "{{ .inputs.domain }}"
84
+
}
85
+
}
86
+
```
87
+
88
+
</TabItem>
89
+
90
+
<TabItemvalue="array">
91
+
92
+
When your action accepts [array entity inputs](/docs/actions-and-automations/create-self-service-experiences/setup-ui-for-action/user-inputs/entity.md#array), you need to extract the identifiers from the array using the `map(.identifier)` pattern:
When users select multiple entities from an [entity array input](/docs/actions-and-automations/create-self-service-experiences/setup-ui-for-action/user-inputs/entity.md#array), the input contains an array of entity objects. Each object includes both `identifier` and `title` properties, but relations can only reference entity identifiers.
107
+
:::
108
+
109
+
</TabItem>
110
+
111
+
<TabItemvalue="flexible">
112
+
113
+
For maximum flexibility, you can create a conditional mapping that handles both single entity and array entity inputs:
114
+
115
+
```json showLineNumbers
116
+
{
117
+
"identifier": "myProjectEntity",
118
+
"title": "My Project",
119
+
"properties": {},
120
+
"relations": {
121
+
"dependencies": "{{ .inputs.dependencies | if type == \"array\" then map(.identifier) else .identifier end }}"
122
+
}
123
+
}
124
+
```
125
+
126
+
This pattern automatically:
127
+
- Extracts identifiers from arrays when multiple entities are selected
128
+
- Uses the identifier directly when a single entity is selected
129
+
130
+
</TabItem>
131
+
132
+
</Tabs>
133
+
134
+
135
+
### Common use cases
136
+
137
+
Here are some typical scenarios for mapping array relations:
Relations can only reference entity **identifiers**, not titles. Even though entity objects contain both `identifier` and `title` properties, you must always use `.identifier` when mapping to relations.
0 commit comments