How to iterate through a list of attributes and join them together in a text string?

Hi, I am trying to pass a new Notion page to google sheets.
The challenge I have is with my “Tags” field, which can contain no tags, one tag, or multiple tags.
Each of which are pulled into Pipedream as separate items.
(see screenshot)

I am trying to create a code step to convert the individual items to a string, but I’m not sure how to access the previous step correctly.

I was given this code by the Pipedream bot, and it does return a string as desired, but I need to pass it the actual values from the previous step (as in the screenshoot)

thank you

export default defineComponent({
  async run({ steps, $ }) {
    const properties = {
      "4": {
        "Contributor": {
          "4": {
            "Tags": {
              "3": {
                "id": "MR~A",
                "type": "multi_select",
                "multi_select": [
                  {
                    "id": "516eda61-dd64-40b8-92e1-8c61533917f5",
                    "name": "Tag 8",
                    "color": "yellow",
                  },
                  {
                    "id": "E{:f",
                    "name": "Tag 1",
                    "color": "default",
                  },
                ],
              },
            },
          },
        },
      },
    };

    const tags = properties["4"]["Contributor"]["4"]["Tags"]["3"]["multi_select"];
    const tagNames = tags.map((tag) => tag.name);
    const tagString = tagNames.join(", ");

    return tagString;
  },
});

Hi @adam1,

To access the values from the previous step, you can use steps.<step_name>.<property>. In your case, you need to replace the properties object in the provided code with the actual data from the previous step. Assuming the previous step is named previous_step, you can modify the code like this:

export default defineComponent({
  async run({ steps, $ }) {
    const properties = steps.previous_step.properties;

    const tags = properties["4"]["Contributor"]["4"]["Tags"]["3"]["multi_select"];
    const tagNames = tags.map((tag) => tag.name);
    const tagString = tagNames.join(", ");

    return tagString;
  },
});

Make sure to replace previous_step with the actual name of the step that contains the properties data.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

This does not work.

I am trying to get just the values of the Tag property, so I am not sure why the numbers and Contributor are referenced in the const tags = properties line