Skip to content

Commit 49a0fb7

Browse files
add trigger workflow for each action
1 parent c79f96f commit 49a0fb7

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import helperFunctions from "../../helper_functions.app.mjs";
2+
3+
export default {
4+
key: "helper_functions-trigger-workflow-for-each",
5+
name: "Trigger Workflow For Each",
6+
description: "Trigger another Pipedream workflow in your workspace for each object in an array.",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
helperFunctions,
11+
workflowId: {
12+
type: "string",
13+
label: "Workflow ID",
14+
description: "The ID of the workflow to trigger. Workflow IDs are formatted as `p_******` and you can find a workflow's ID within the workflow builder URL.",
15+
},
16+
objects: {
17+
type: "any",
18+
label: "Array of Objects",
19+
description: "Use a custom expression (`{{steps.code.objects}}`) to reference an array of objects exported from a previous step to send to the triggered workflow.",
20+
},
21+
},
22+
async run({ $ }) {
23+
const {
24+
workflowId,
25+
objects,
26+
} = this;
27+
28+
try {
29+
const results = [];
30+
const triggerPromises = objects.map((object) => $.flow.trigger(workflowId, object));
31+
for await (const result of triggerPromises) {
32+
results.push(result);
33+
}
34+
$.export("$summary", `Successfully triggered workflow ID **${workflowId}**`);
35+
return results;
36+
} catch (error) {
37+
$.export("$summary", `Failed to trigger workflow ID **${workflowId}**.`);
38+
throw error;
39+
}
40+
},
41+
};

0 commit comments

Comments
 (0)