How to Skip a Workflow Step If a PDF Page Isn't Created?

This topic was automatically generated from Slack. You can find the original thread here.

Hey, is there any way to skip a step if a condition isn’t met?

ie: I’m creating a PDF earlier in the workflow. Sometimes it’s 2 pages, sometimes its 3.
Later in the workflow, I’m adding those PDF pages to a Google Doc. Each instance of adding a PDF to the doc has its own step. But I’m getting an error if the PDF created only has two pages, but I have 3 steps.

So is there a way to check whether that PDF URL is present, and if it isn’t, just skip that step? (Hope that made sense)

Hey is there any way to skip a step if a condition isn’t met?

ie: I’m creating a PDF earlier in the workflow. Sometimes it’s 2 pages, sometimes its 3.
Later in the workflow, I’m adding those PDF pages to a Google Doc. Each instance of adding a PDF to the doc has its own step. But I’m getting an error if the PDF created only has two pages, but I have 3 steps.

So is there a way to check whether that PDF URL is present, and if it isn’t, just skip that step? (Hope that made sense)

Yes, you can conditionally skip a step in your workflow based on whether a PDF URL is present. You can achieve this by using a code step to check the condition and only proceed if the condition is met. If the condition is not met, you can use $.flow.exit() to end the workflow early. Here’s an example of how you can achieve this: 1. Check for the PDF URL: Add a code step before the steps that add the PDF pages to the Google Doc. This step will check if the PDF URL is present. 2. Conditionally execute the steps: Use $.flow.exit() to skip the steps if the PDF URL is not present. Here’s an example Pipedream component that demonstrates this: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { google: { type: "app", app: "google", }, pdfUrl: { type: "string", label: "PDF URL", }, }, async run({ steps, $ }) { // Check if the PDF URL is present if (!this.pdfUrl) { return $.flow.exit("PDF URL is not present. Skipping this step."); } // If the PDF URL is present, proceed with adding the PDF to the Google Doc return await axios($, { url: `https://www.googleapis.com/oauth2/v1/userinfo`, headers: { Authorization: `Bearer ${this.google.$auth.oauth_access_token}`, }, }); }, }); In this example: - The pdfUrl prop is used to pass the PDF URL to the component. - The code checks if the pdfUrl is present. If it is not, it calls $.flow.exit() with a message to skip the step. - If the pdfUrl is present, it proceeds with the rest of the code to add the PDF to the Google Doc. You can add similar code steps before each step that adds a PDF page to the Google Doc to conditionally skip those steps if the PDF URL is not present. If you have any further questions or need additional assistance, feel free to ask!