When Should I Use `$.export` Instead of `return` to Pass Data to Other Workflow Steps?

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

In what case should i use $.export to pass data to other workflow steps instead of using return?

In what case should i use $.export to pass data to other workflow steps instead of using return?

You should use $.export to pass data to other workflow steps when you want to create named exports—that is, when you want to expose multiple values or give specific names to the data you export from a step. Here’s a breakdown of when to use each: ### Use return when: - You only need to export a single value from a step. - The value will be accessible in downstream steps as steps.[STEP NAME].$return_value. Example: async run({ $ }) { return "myValue"; } // Access in next step: steps.stepName.$return_value ### Use $.export when: - You want to export multiple values from a single step, each with its own name. - You want to give the exported value a specific, meaningful name. - The exported values will be accessible in downstream steps as steps.[STEP NAME].[EXPORT NAME]. Example: async run({ $ }) { $.export("foo", "bar"); $.export("baz", 123); } // Access in next step: steps.stepName.foo and steps.stepName.baz Key points: - return is simple and good for a single value. - $.export is more flexible for multiple or named values. - Both methods make the data available to downstream steps, but the way you reference the data is different. Reference: See the Pipedream docs on returning data from steps and using $.export.

Ah! TIL: $.export alleviates the need for $return_value in the subsequent steps.

It’s like $return_value is the default export name, but $.export allows you to specify something else instead.

I wonder what happens if we use both? :thinking_face: :exploding_head:

I assume return would override $.export.

Ah! Both are there!

:sweat_smile: :ok_hand:

I will be using $.export from now on. :smile:

Thanks ! :pray: