Problem with line items in code (JS)

  • 5 June 2020
  • 2 replies

Userlevel 1



I’m getting stuck with the JS code. Basically I’m getting single line of order from WooCommerce, counting the quantity of products for this line and creating number of rows in Google Sheets that equals the quantity. 

In order to do this I’ve created Code block that should return line items that can be used later to create Google Sheet record. 

My code is here:

The test runs gives such output :


However in following step - creating Google Sheets record - I’m not getting Line item support:

only separete lines. So runnig this zap will create only one row in Google Sheet. 

What am I doing wrong? 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +12

Hi @Marcin! Hmm, you’re right, it looks like the line items have been made correctly given the output of the code step. I wonder if anyone who has experience with code steps is able to help here, maybe @ikbelkirasan?

Userlevel 7
Badge +12

@Danvers - Sure, I will try and help :)

@Marcin - That issue you’re seeing is basically due to your use of an object that is 1-based indexed. Thus, in order to get line items to work as expected, you should actually use an array. Take a look at the code snippet below:

const items = []

for (let i = 1; i <= parseInt(inputData.iloscPokoi); i++) {
nr_projektu: inputData.nrProjektu,
rodzaj: inputData.rodzajPokoju,
nr_pokoju_w_zamowjeniu: i,
klient: inputData.klient

output = [{ items }]