Skip to main content
Question

Javascript result with object is in next code zap string

  • 8 June 2024
  • 1 reply
  • 15 views

Hello,

i have written some code to parse and prepare input data and use it later and my result/return code is:

...
for(..){
mapped[sku] = [name,variant,quantity];
}
...
let resultMap = {
"resultStr":resultStr,
"mapped":mapped
};

return resultMap;

the test seems to be fine: (the map is containing a key and an array with 3 values)

i also debugged it:

return {"debug":{}.toString.call(resultMap.mapped ).split(' ')[1].slice(0, -1).toLowerCase()};

which returned: object

and also the value of the map:

return {"debug":{}.toString.call(resultMap.mapped[lastSku] ).split(' ')[1].slice(0, -1).toLowerCase()}; 

which returned: array

 

when i use it in an nother code zap (javascript) and make the input:

and i use it like:

let curitemMap = input.itemMap;

for(let itemSku in curitemMap){
...
}

it was iterating over each letter. then i debugged and the curitemMap is a string.

So is it possible to keep my object as it was? alternative would be to pass it as json and parse it afterwards… but i think it should be possible so?

 

Just for info: i also asked the AI for help and it also created the code as i did.

 

1 reply

Userlevel 7
Badge +14

Hi @wwolf 

Help articles for using Code: https://zapier.com/apps/code/help

Inputs are converted to strings.

You can also define data fields to be provided to the code as strings with the Input Data fields.

 

Options for handling line items:

 

How to get the RAW JSON:

 

Reply