-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamics-365-sales-index-accounts.bpmn
343 lines (336 loc) · 17 KB
/
dynamics-365-sales-index-accounts.bpmn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bioc="http://bpmn.io/schema/bpmn/biocolor/1.0" xmlns:color="http://www.omg.org/spec/BPMN/non-normative/color/1.0" id="Definitions_0sdny8d" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="5.2.0">
<bpmn:collaboration id="Collaboration_1vlu0n3">
<bpmn:participant id="Participant_1b38ks9" name="INDEX ACCOUNTS" processRef="dynamics-365-sales-index-accounts" />
</bpmn:collaboration>
<bpmn:process id="dynamics-365-sales-index-accounts" name="Onify Blueprint: Index accounts from Dynamics 365 Sales" isExecutable="true">
<bpmn:laneSet id="LaneSet_02o4jdr">
<bpmn:lane id="Lane_0ougcvv" name="ONIFY">
<bpmn:flowNodeRef>start</bpmn:flowNodeRef>
<bpmn:flowNodeRef>getSettings</bpmn:flowNodeRef>
<bpmn:flowNodeRef>transformAccounts</bpmn:flowNodeRef>
<bpmn:flowNodeRef>indexItems</bpmn:flowNodeRef>
<bpmn:flowNodeRef>Gateway_08t9pgy</bpmn:flowNodeRef>
<bpmn:flowNodeRef>end</bpmn:flowNodeRef>
</bpmn:lane>
<bpmn:lane id="Lane_10vswlw" name="D365">
<bpmn:flowNodeRef>generateAccessToken</bpmn:flowNodeRef>
<bpmn:flowNodeRef>getAccounts</bpmn:flowNodeRef>
</bpmn:lane>
</bpmn:laneSet>
<bpmn:startEvent id="start" name="Index accounts">
<bpmn:outgoing>Flow_0wk332j</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:serviceTask id="generateAccessToken" name="Generate Azure access token">
<bpmn:extensionElements>
<camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="form">
<camunda:map>
<camunda:entry key="client_id">${environment.output.settings._azure_credentials.client_id}</camunda:entry>
<camunda:entry key="scope">${environment.output.settings._dynamics365_url}/.default</camunda:entry>
<camunda:entry key="client_secret">${environment.output.settings._azure_credentials.client_secret}</camunda:entry>
<camunda:entry key="grant_type">client_credentials</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="responseType">json</camunda:inputParameter>
<camunda:inputParameter name="method">POST</camunda:inputParameter>
<camunda:inputParameter name="headers">
<camunda:map>
<camunda:entry key="Content-Type">application/x-www-form-urlencoded</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="url">https://login.microsoftonline.com/${environment.output.settings._azure_credentials.tenant}/oauth2/v2.0/token</camunda:inputParameter>
</camunda:inputOutput>
<camunda:connectorId>httpRequest</camunda:connectorId>
</camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="state">
<camunda:script scriptFormat="js">next(null, {name: content.name, id: content.id});</camunda:script>
</camunda:inputParameter>
<camunda:outputParameter name="accessToken">${content.output.body.access_token}</camunda:outputParameter>
<camunda:outputParameter name="state">
<camunda:script scriptFormat="js">next(null, {id: content.id, result: {done: true}});</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_1l3tv0h</bpmn:incoming>
<bpmn:outgoing>Flow_0t7vdw4</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:serviceTask id="getAccounts" name="Get accounts">
<bpmn:extensionElements>
<camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="responseType">json</camunda:inputParameter>
<camunda:inputParameter name="headers">
<camunda:map>
<camunda:entry key="Authorization">Bearer ${environment.output.accessToken}</camunda:entry>
<camunda:entry key="Prefer">odata.include-annotations="*", odata.maxpagesize=30</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="url">
<camunda:script scriptFormat="js">const url = environment.output.nextLink ? environment.output.nextLink : `${environment.output.settings._dynamics365_url}/api/data/v9.2/accounts`;
next(null, url);</camunda:script>
</camunda:inputParameter>
<camunda:inputParameter name="throwHttpErrors">${true}</camunda:inputParameter>
<camunda:inputParameter name="method">GET</camunda:inputParameter>
</camunda:inputOutput>
<camunda:connectorId>httpRequest</camunda:connectorId>
</camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="setItemsCount">
<camunda:script scriptFormat="js">environment.output.itemsCount = (environment.output.itemsCount > 0) ? environment.output.itemsCount : 0;
next();</camunda:script>
</camunda:inputParameter>
<camunda:inputParameter name="state">
<camunda:script scriptFormat="js">next(null, {name: content.name, id: content.id});</camunda:script>
</camunda:inputParameter>
<camunda:outputParameter name="accounts">${content.output.body.value}</camunda:outputParameter>
<camunda:outputParameter name="nextLink">
<camunda:script scriptFormat="js">next(null, content.output.body['@odata.nextLink']);</camunda:script>
</camunda:outputParameter>
<camunda:outputParameter name="state">
<camunda:script scriptFormat="js">next(null, {id: content.id, result: {done: true}});</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0t7vdw4</bpmn:incoming>
<bpmn:incoming>Flow_15e3t8t</bpmn:incoming>
<bpmn:outgoing>Flow_07nd58u</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_07nd58u" sourceRef="getAccounts" targetRef="transformAccounts" />
<bpmn:sequenceFlow id="Flow_0t7vdw4" sourceRef="generateAccessToken" targetRef="getAccounts" />
<bpmn:sequenceFlow id="Flow_0wk332j" sourceRef="start" targetRef="getSettings" />
<bpmn:sequenceFlow id="Flow_1l3tv0h" sourceRef="getSettings" targetRef="generateAccessToken" />
<bpmn:serviceTask id="getSettings" name="Get settings">
<bpmn:extensionElements>
<camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="query">
<camunda:map>
<camunda:entry key="tag">dynamics365</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="url">/my/config/settings</camunda:inputParameter>
</camunda:inputOutput>
<camunda:connectorId>onifyApiRequest</camunda:connectorId>
</camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="state">
<camunda:script scriptFormat="js">next(null, {name: content.name, id: content.id});</camunda:script>
</camunda:inputParameter>
<camunda:outputParameter name="settings">${content.output.body}</camunda:outputParameter>
<camunda:outputParameter name="state">
<camunda:script scriptFormat="js">next(null, {id: content.id, result: {done: true}});</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0wk332j</bpmn:incoming>
<bpmn:outgoing>Flow_1l3tv0h</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:scriptTask id="transformAccounts" name="Transform accounts" scriptFormat="javascript" camunda:resultVariable="itemsToIndex">
<bpmn:incoming>Flow_07nd58u</bpmn:incoming>
<bpmn:outgoing>Flow_06nzi8a</bpmn:outgoing>
<bpmn:script>if (!environment.output.accounts) {
next(null, []);
}
const itemsToIndex = [];
environment.output.accounts.forEach(async function(account) {
const itemToIndex = {
type: "account",
key: account.accountid.replace(/[-]/g, '').toLowerCase(),
name: account.name,
description: (account.description ? account.description : null),
tag: ["dynamics365", "account"],
owner: account['_ownerid_value@Microsoft.Dynamics.CRM.lookuplogicalname'],
status: account['statuscode@OData.Community.Display.V1.FormattedValue'],
attribute: {
accountnumber: account.accountnumber,
_etag : account['@odata.etag'],
_accountid: account.accountid,
address1_city: account.address1_city,
address1_line1: account.address1_line1,
address1_postalcode: account.address1_postalcode,
telephone1: account.telephone1
}
};
itemsToIndex.push(itemToIndex);
environment.output.itemsCount++;
})
next(null, itemsToIndex);</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="Flow_06nzi8a" sourceRef="transformAccounts" targetRef="indexItems" />
<bpmn:serviceTask id="indexItems" name="Index accounts">
<bpmn:extensionElements>
<camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="payload">${environment.output.itemsToIndex}</camunda:inputParameter>
<camunda:inputParameter name="method">POST</camunda:inputParameter>
<camunda:inputParameter name="url">/admin/bulk/items</camunda:inputParameter>
</camunda:inputOutput>
<camunda:connectorId>onifyApiRequest</camunda:connectorId>
</camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="state">
<camunda:script scriptFormat="js">next(null, {name: content.name, id: content.id});</camunda:script>
</camunda:inputParameter>
<camunda:outputParameter name="state">
<camunda:script scriptFormat="js">let logMessage = `Indexed ${environment.output.itemsCount} accounts (${environment.options.name}, ${environment.settings.processId})`;
environment.services.onifyApiRequest.call({
id: content.id,
name: content.name,
environment,
}, {
url: `/tools/logs`,
method: 'POST',
payload: {
level: 'info',
message: logMessage,
meta: {
tag: ['index'],
key: 'key1',
processId: environment.settings.processId
}
}
});
next(null, {
id: content.id,
result: {
statusmessage: logMessage
}
});</camunda:script>
</camunda:outputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_06nzi8a</bpmn:incoming>
<bpmn:outgoing>Flow_0a65bzo</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_0a65bzo" sourceRef="indexItems" targetRef="Gateway_08t9pgy" />
<bpmn:exclusiveGateway id="Gateway_08t9pgy" default="Flow_0g42nz5">
<bpmn:incoming>Flow_0a65bzo</bpmn:incoming>
<bpmn:outgoing>Flow_0g42nz5</bpmn:outgoing>
<bpmn:outgoing>Flow_15e3t8t</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_0g42nz5" name="No more accounts" sourceRef="Gateway_08t9pgy" targetRef="end" />
<bpmn:endEvent id="end" name="Accounts indexed">
<bpmn:extensionElements>
<camunda:inputOutput>
<camunda:inputParameter name="clearOutput">
<camunda:script scriptFormat="js">// Do not bloat flow state
environment.output.accounts = [];
environment.output.itemsToIndex = [];
// Do not save secrets in state
environment.output.azureCredentials = {};
next();</camunda:script>
</camunda:inputParameter>
<camunda:inputParameter name="state">
<camunda:script scriptFormat="js">next(null, {
id: 'indexItems',
result: {
done: true
}
});</camunda:script>
</camunda:inputParameter>
</camunda:inputOutput>
</bpmn:extensionElements>
<bpmn:incoming>Flow_0g42nz5</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="Flow_15e3t8t" name="Get more accounts" sourceRef="Gateway_08t9pgy" targetRef="getAccounts">
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${environment.output.nextLink}</bpmn:conditionExpression>
</bpmn:sequenceFlow>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1vlu0n3">
<bpmndi:BPMNShape id="Participant_1b38ks9_di" bpmnElement="Participant_1b38ks9" isHorizontal="true">
<dc:Bounds x="161" y="120" width="1429" height="430" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Lane_10vswlw_di" bpmnElement="Lane_10vswlw" isHorizontal="true">
<dc:Bounds x="191" y="330" width="1399" height="220" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Lane_0ougcvv_di" bpmnElement="Lane_0ougcvv" isHorizontal="true">
<dc:Bounds x="191" y="120" width="1399" height="210" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_15e3t8t_di" bpmnElement="Flow_15e3t8t">
<di:waypoint x="1310" y="235" />
<di:waypoint x="1310" y="510" />
<di:waypoint x="790" y="510" />
<di:waypoint x="790" y="460" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1247" y="256" width="46" height="27" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0g42nz5_di" bpmnElement="Flow_0g42nz5">
<di:waypoint x="1335" y="210" />
<di:waypoint x="1482" y="210" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1355" y="183" width="90" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0a65bzo_di" bpmnElement="Flow_0a65bzo">
<di:waypoint x="1230" y="210" />
<di:waypoint x="1285" y="210" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_06nzi8a_di" bpmnElement="Flow_06nzi8a">
<di:waypoint x="1040" y="210" />
<di:waypoint x="1130" y="210" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1l3tv0h_di" bpmnElement="Flow_1l3tv0h">
<di:waypoint x="480" y="210" />
<di:waypoint x="530" y="210" />
<di:waypoint x="530" y="420" />
<di:waypoint x="570" y="420" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0wk332j_di" bpmnElement="Flow_0wk332j">
<di:waypoint x="288" y="210" />
<di:waypoint x="379" y="210" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0t7vdw4_di" bpmnElement="Flow_0t7vdw4">
<di:waypoint x="670" y="420" />
<di:waypoint x="740" y="420" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_07nd58u_di" bpmnElement="Flow_07nd58u">
<di:waypoint x="840" y="420" />
<di:waypoint x="910" y="420" />
<di:waypoint x="910" y="210" />
<di:waypoint x="940" y="210" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="start" bioc:stroke="#43a047" bioc:fill="#c8e6c9" color:background-color="#c8e6c9" color:border-color="#43a047">
<dc:Bounds x="252" y="192" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="234" y="235" width="75" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1mbrrq0_di" bpmnElement="generateAccessToken">
<dc:Bounds x="570" y="380" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BPMNShape_0l754w1" bpmnElement="getAccounts">
<dc:Bounds x="740" y="380" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0yibfwb_di" bpmnElement="getSettings">
<dc:Bounds x="379" y="170" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0v82xsa_di" bpmnElement="transformAccounts">
<dc:Bounds x="940" y="170" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_03ti1bi_di" bpmnElement="indexItems">
<dc:Bounds x="1130" y="170" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_08t9pgy_di" bpmnElement="Gateway_08t9pgy" isMarkerVisible="true">
<dc:Bounds x="1285" y="185" width="50" height="50" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_10fxhsy_di" bpmnElement="end" bioc:stroke="#e53935" bioc:fill="#ffcdd2" color:background-color="#ffcdd2" color:border-color="#e53935">
<dc:Bounds x="1482" y="192" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="1458" y="235" width="86" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>