how do I have a conditional branch that triggers two different work flows based on if the result from a query database action is empty or not
To create a conditional branch that triggers two different workflows based on whether the result from a “Query Database” action is empty or not, you can use a code step with an if
statement to check the results and then use the $.send.http()
function to make an HTTP request to trigger the desired workflows. Here’s an example: 1. Add the “Query Database” action as described in the Notion — Query Database documentation. 2. Add a code step after the “Query Database” action. 3. In the code step, use the following code to check if the results are empty and trigger the appropriate workflows: export default defineComponent({ async run({ steps }) { const results = steps.query_database.result; // Replace "query_database" with the name of your "Query Database" action step if (results.length > 0) { // Results are not empty, trigger Workflow 1 await $.send.http({ method: "POST", url: "https://api.pipedream.com/v1/sources/{YOUR_SOURCE_ID}/event", // Replace {YOUR_SOURCE_ID} with the source ID of Workflow 1 headers: { "Authorization": `Bearer {YOUR_API_KEY}` // Replace {YOUR_API_KEY} with your Pipedream API key }, data: { results: results } }); } else { // Results are empty, trigger Workflow 2 await $.send.http({ method: "POST", url: "https://api.pipedream.com/v1/sources/{YOUR_SOURCE_ID}/event", // Replace {YOUR_SOURCE_ID} with the source ID of Workflow 2 headers: { "Authorization": `Bearer {YOUR_API_KEY}` // Replace {YOUR_API_KEY} with your Pipedream API key }, data: { message: "No results found" } }); } }, });
Replace {YOUR_SOURCE_ID}
with the source ID of the respective workflows you want to trigger and {YOUR_API_KEY}
with your Pipedream API key. This code step checks if the results are empty and triggers the appropriate workflow using an HTTP request to the Pipedream API.
modify the above code block to send the page id of the first element if there was a page found
Here’s the modified code block that sends the page ID of the first element if a page was found: import { axios } from "@pipedream/platform"; export default defineComponent({ async run({ steps }) { const results = steps.query_database.result; // Replace "query_database" with the name of your "Query Database" action step if (results.length > 0) { // Results are not empty, trigger Workflow 1 with the page ID of the first element const firstPageId = results[0].id; await $.send.http({ method: "POST", url: "https://api.pipedream.com/v1/sources/{YOUR_SOURCE_ID}/event", // Replace {YOUR_SOURCE_ID} with the source ID of Workflow 1 headers: { "Authorization": `Bearer {YOUR_API_KEY}` // Replace {YOUR_API_KEY} with your Pipedream API key }, data: { pageId: firstPageId } }); } else { // Results are empty, trigger Workflow 2 await $.send.http({ method: "POST", url: "https://api.pipedream.com/v1/sources/{YOUR_SOURCE_ID}/event", // Replace {YOUR_SOURCE_ID} with the source ID of Workflow 2 headers: { "Authorization": `Bearer {YOUR_API_KEY}` // Replace {YOUR_API_KEY} with your Pipedream API key }, data: { message: "No results found" } }); } }, });
Replace {YOUR_SOURCE_ID}
with the source ID of the respective workflows you want to trigger and {YOUR_API_KEY}
with your Pipedream API key. This code step checks if the results are empty and triggers the appropriate workflow using an HTTP request to the Pipedream API. If a page is found, it sends the page ID of the first element.
How do I find the source id and api key?
To find your Source ID, follow these steps: 1. Open https://pipedream.com/sources and click on your event source. 2. Copy the URL that appears in your browser’s address bar. For example: https://pipedream.com/sources/dc_abc123
3. Your source’s ID is the value that starts with dc_
. In this example: dc_abc123
. To obtain your API key, you need to create a Pipedream CLI profile: 1. Install the Pipedream CLI and run pd login
in your terminal. 2. The CLI will open a browser asking you to log in to your Pipedream account. 3. After logging in, the CLI writes the API key for that account to your config file, in the api_key
field. You can also find your API key in the Pipedream config file. The API key will be listed under the api_key
field. Remember to keep your API key secure and not share it with others.
How can I stop a work flow if something is null
To stop a workflow if a value is null, you can use the $.flow.exit()
method in a code step. Here’s an example: export default defineComponent({ async run({ steps }) { // Replace "steps.some_step" with the actual step you want to check for null const valueToCheck = steps.some_step.result; if (valueToCheck === null) { console.log("Value is null, stopping the workflow"); return $.flow.exit(); } // Continue with the rest of your workflow logic }, });
In this example, replace steps.some_step
with the step you want to check for a null value. If the value is null, the workflow will stop executing at that point.
it says $ is not defined when I run the previous step
I apologize for the confusion. It seems there was an issue with the code I provided earlier. Please try the following modified code block: export default defineComponent({ async run({ steps }) { const results = steps.query_database.result; // Replace "query_database" with the name of your "Query Database" action step if (results.length > 0) { // Results are not empty, trigger Workflow 1 with the page ID of the first element const firstPageId = results[0].id; await this.$send.http({ method: "POST", url: "https://api.pipedream.com/v1/sources/{YOUR_SOURCE_ID}/event", // Replace {YOUR_SOURCE_ID} with the source ID of Workflow 1 headers: { "Authorization": `Bearer {YOUR_API_KEY}` // Replace {YOUR_API_KEY} with your Pipedream API key }, data: { pageId: firstPageId } }); } else { // Results are empty, trigger Workflow 2 await this.$send.http({ method: "POST", url: "https://api.pipedream.com/v1/sources/{YOUR_SOURCE_ID}/event", // Replace {YOUR_SOURCE_ID} with the source ID of Workflow 2 headers: { "Authorization": `Bearer {YOUR_API_KEY}` // Replace {YOUR_API_KEY} with your Pipedream API key }, data: { message: "No results found" } }); } }, });
In this updated code, I replaced $.send.http
with this.$send.http
. This should resolve the “$ is not defined” error.
Give me a code block to stop workflow if a value is null
Here’s a code block to stop a workflow if a value is null: export default defineComponent({ async run({ steps }) { // Replace "steps.some_step.result" with the actual value you want to check for null const valueToCheck = steps.some_step.result; if (valueToCheck === null) { console.log("Value is null, stopping the workflow"); return; } // Continue with the rest of your workflow logic }, });
In this example, replace steps.some_step.result
with the value you want to check for null. If the value is null, the workflow will stop executing at that point.
What command can I return to exit a work flow
To stop a workflow execution in a code step, you can simply use the return
statement. If a certain condition is met and you want to exit the workflow, just return from the run
method. Here’s an example: export default defineComponent({ async run({ steps }) { // Replace "steps.some_step.result" with the actual value you want to check for null const valueToCheck = steps.some_step.result; if (valueToCheck === null) { console.log("Value is null, stopping the workflow"); return; } // Continue with the rest of your workflow logic }, });
In this example, replace steps.some_step.result
with the value you want to check for null. If the value is null, the workflow will stop executing at that point.
my next steps runs after this and continues to give me an error
I apologize for the confusion earlier. To prevent the next step from running when a value is null, you can use the end
property of the step in the Pipedream UI. Here’s how: 1. Click on the step you want to skip in the workflow editor. 2. In the step settings panel on the right, expand the “Advanced” section. 3. Set the “Skip if previous step” dropdown to “ended”. 4. Save the changes. Now, if the previous step ends due to a null value, the next step will be skipped, and the workflow will continue with the following steps.
how do I access advanced settings
I apologize for any confusion earlier. To access the advanced settings for a step in a Pipedream workflow, please follow these steps: 1. Open your workflow in the Pipedream UI. 2. Click on the step for which you want to access the advanced settings. 3. In the step settings panel on the right side of the screen, you should see an “Advanced” section. Expand the “Advanced” section to view and modify the advanced settings for the selected step.