How Can I Transfer Data from a Data Store to Two Columns in Google Sheets?

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

Hi I have my data in a data store. How do I put that into 2 columns of google sheets? So far I have get_all_records->create_worksheet->add_multiple_rows but when I supply the data as {{steps.get_all_records.$return_value}} its not in the array of arrays format so generates an error. Everything else I’m doing ends up with 5+ workflow steps so there has to be a better way!

Google Sheet - Add Multiple Rows Row Values prop accepts an array of array (For example [["Foo",1,2],["Bar",3,4]]). So you might need to add the transform code in your get_all_records step to return the expected value.

Thanks. Transform code is a workflow step or needs manually writing?

It needs manual writing in a code step. If you’d like to have specific prop to map, you can use Add Single Row

30 mins later…

I can’t believe cut & paste doesnt work on this :rolling_on_the_floor_laughing:. I’ll try again tomorrow.

OK, I’m not giving up. I made something that works but I can’t save it as an action for future use (as usual). Can you help? I’m getting Cannot read property ‘get_all_records’ of undefined.

THIS WORKS:
export default defineComponent({
props: {
myDataStore: {
type: “data_store”,
},
},
async run({ steps, $ }) {
const data = steps.get_all_records.$return_value;
let csv = “key,value\n”;
for (const key of Object.keys(data)) {
csv += "${key}","${data[key]}"\n;
}
return csv;
},
});

THIS DOES NOT WORK:
export default defineComponent({
name: “Data Store to CSV”,
key: “data-store-to-csv”,
version: “0.0.1”,
type: “action”,
props: {
foo: {
type: “data_store”,
label: “Data Store”,
},
steps: {
type: “object”,
label: “Steps”,
description: “The steps object”,
},
},
async run({ steps, $ }) {
const data = steps.get_all_records.$return_value;
let csv = “key,value\n”;
for (const key of Object.keys(data)) {
csv += "${key}","${data[key]}"\n;
}
return csv;
},
});

, for action, you need to use the data in your prop instead of using data from the steps . After having the prop, you can put the expression that refer to the data from the previous step.

For example:

// To reuse this code as an action, make sure to publish it to "My Actions"
// using the dropdown menu in the top right corner of this step.

export default defineComponent({
  name: "Example publishable action",
  key: "your-unique-action-key",
  version: "0.0.1",
  type: "action",
  props: {
    all_records: {
      type: "string",
      label: "All Records",
    },
  },
  async run({ $ }) {
    console.log(this.all_records)
  },
})

You can read more about action development here: Quickstart: Action Development

I have completed the course without understanding the material :grimacing:
I’ll keep at it. I have it working now. Thanks for the help!