Skip to content
How to Get Line Ite...
 
Notifications
Clear all

How to Get Line Items/Arrays into Code Steps | callin.io Community

17 Posts
14 Users
0 Reactions
9 Views
TimS
 TimS
(@tims)
Posts: 7
Active Member
Topic starter
 

Tim here from the callin.io Support Team with a workflow idea!

Background

If you’re familiar with the Code by callin.io app, you’re probably used to working with all kinds of values, including arrays. In callin.io, arrays are generally called “Line Items” and sometimes it can be tricky to get them into a Code Step unscathed to run them through some custom process.

Why is it difficult? All values added to the Input Data fields of a Code Step are converted into Strings and sent into the Code Step in that format. Arrays / Line Items get converted into Strings that are comma separated values. While it’s definitely possible to split those comma separated values back into arrays inside the code, we run into problems if the values themselves contain commas.

To further complicate things, if we’re sending multiple properties of line items (multiple arrays that relate to each other) and some of the arrays have null or empty values, those will be completely dropped, so it can cause our input data to become misaligned.

So how can we work around this?

The Feature Request

First, please write in to support to ask to add your voice to the feature request that we have open to support proper line item input in the Input Data fields for the Code by callin.io Actions.

The Solution

For now, we can use the Formatter by callin.io app’s Utilities Action: Line-item to Text Transform to help us out. 

Note: The Code below is in Javascript but this can be adapted for Python Code Steps as well.

Let’s look at our input values first:

Image: 176db780 9473 49a1 b14a 9e731e1e1bb8

I’ve added an “easy” input first to show how we’d normally get arrays into a Code Step where we don’t need more help. There is also an example with a comma in an element, and another with a null element.

Here’s our default Code Step trying to turn the strings back into arrays:

Image: 996f51f9 5897 4c32 b04c cac72401fe6e

Let’s take a look at the output:

Image: d958f18c 12d1 4057 910b e780206d59a4

As we can see, the array with comma containing element now has 4 elements instead of 3 as the green,blue element was split up. The array with the null element has lost that element, reducing it from 4 elements to 3.

Let’s add a Formatter Utilities Action: Line-item to Text Transform to add our own delimiter:

Image: 90e5542b c1da 4e4b 8e00 1782fc44bb46

This gives us a text output with a different delimiter: 

Image: 1a88832a 1997 4cff 8c2e f28c57635013

Now we can run this through the Code Step:

Image: 04ad4965 db55 44bc a904 482934342eb7

And we get the result we wanted where the value with a comma doesn’t get split into multiple elements:

Image: c8fac35f 25e3 4482 9268 c0f259fbcdb4

 

Let’s go back and create another Formatter Utilities Action: Line-item to Text Transform to take care of the array with the null value in it. This time, we also add a `-` after the line item input. 

Image: 3beb4982 0d5e 4d09 9b75 4f17b9ea34ba

 

It could be any single character, and what it does is it adds the text - to each element of the line item/array, even the null elements, so that those aren’t dropped. Here’s the output:

Image: 10706213 400e 4588 8c85 5659957f4357

 

Now we can split on our custom delimiter and then remove the last character from each element inside the Code Step. Here’s how we do that:

Image: c5e139ee 692d 4f35 9bce c02618ea1df9

 

The slice(0,-1) returns the string with the last character removed, so we can get back to our original elements. Here’s our fixed output with the null element in tact:

Image: 5b20ca28 d93d 46e1 bb6e 7f170fcf9dd0

Here’s that final code snippet if you want to copy it and try it out:

const { lineItemEasy, lineItemWithComma, lineItemWithNull } = inputData; const lineItemEasyArray = lineItemEasy.split(','); const lineItemWithCommaArray = lineItemWithComma.split('|||'); const lineItemWithNullArray = lineItemWithNull.split('|||'); const lineItemWithNullArrayFixed = lineItemWithNullArray.map((element) => { return element.slice(0,-1); }); output = [{ lineItemEasyArray, lineItemWithCommaArray, lineItemWithNullArrayFixed, }];

Once you have your Line item values inside your code step with all elements preserved properly, it will be easier to write code to process them in various ways.

Bonus: For a slightly more advanced approach to the above problem but for multiple, related line-item properties, you can also take a look at the answer to the question that inspired this post here: 

https://community.zapier.com/ask-the-community-3/line-items-as-array-in-code-step-4224

I hope these workarounds help you make more use of the Code by callin.io app!

Tim

 

Please Note

This code is provided as is, without warranty, but we’ll do our best to answer questions you have about it here.

Supporting custom code is outside of the scope of callin.io Support, so if you need help with this, or other code you’re working on, the best place to ask is here in the callin.io community and/or on Stack Overflow. You’re still welcome to ask in Support via our contact form just in case it’s something unrelated to the code that isn’t working, but you may be directed to one of these resources to get help from the community. 

 
Posted : 04/08/2025 8:30 am
FabienK
(@fabienk)
Posts: 1
New Member
 

Man, finding this step very useful to work around.

Now, 9 months later, nothing has been done yet… hum

 
Posted : 20/09/2021 12:00 am
SamB
 SamB
(@samb)
Posts: 71
Trusted Member
 

Hey ,

Glad to hear you’re making good use of Tim’s suggested workaround! : )

I’ve added your vote to the feature request to support line item input on Code by callin.io steps. We don’t have an ETA on this but we’ll be sure to contact you by email as soon as it’s added! 

 
Posted : 20/09/2021 12:00 am
WAV-Tech
(@wav-tech)
Posts: 1
New Member
 

Having line item input data would be great.

 
Posted : 29/09/2021 12:00 am
christina.d
(@christina-d)
Posts: 13
Active Member
 

Understood! I've added your vote to the feature request. We'll make sure to keep you and the thread informed if this is implemented. 🙂

 
Posted : 29/09/2021 12:00 am
IvanStaykov
(@ivanstaykov)
Posts: 2
New Member
 

I'm attempting to use this code:

 

const {
  productname,
  productdescription,
  productprice,
  productquantity,
  productsum,
  productdiscount,
  producttotal,
  productcode,
} = inputData;

const productnameArray = productname.split(',');
const productdescriptionArray = productdescription.split(',');
const productpriceArray = productprice.split(',');
const productquantityArray = productquantity.split(',');
const productsumArray =  productsum.split(',');
const productdiscountArray =  productdiscount.split(',');
const producttotalArray = producttotal.split(',');
const productcodeArray = productcode.split(',');

output = [{
  productnameArray,
  productdescriptionArray,
  productpriceArray,
  productquantityArray,
  productsumArray,
  productdiscountArray,
  producttotalArray,
  productcodeArray,
}];

 

However, it's returning a TypeError: Cannot read property 'split' of undefined.

Any suggestions?

 
Posted : 01/04/2022 12:00 am
IvanStaykov
(@ivanstaykov)
Posts: 2
New Member
 

When I limit the keys to just one, it functions correctly.

However, in this scenario, the output is still presented as an array, instead of individual values.

Do you have any suggestions on how I can properly split this into separate values?

Ideally, I'd like to transform the input from:

Product Names: Product Name 1, Product Name 2, Product Name 3

to an output that looks like this:

Product Name 1

Product Name 2

Product Name 3

 

I need to incorporate these into a Google Docs template that uses:

{{productname1}}

{{productname2}}

{{productname3}}

Therefore, I require the output for each value individually, rather than as a single array. I'm uncertain if my explanation is clear 🙁

 
Posted : 01/04/2022 12:00 am
comanr admin
(@comanr-admin)
Posts: 1
New Member
 

I spent a full workday searching for a workaround for this issue, and I appreciate you sharing this guide! It was indeed quite frustrating trying to determine if the problem lay with my code or the incoming data. Please address this!

 
Posted : 28/09/2022 12:00 am
KurtUhlir
(@kurtuhlir)
Posts: 1
New Member
 
IvanStaykov wrote:

When I leave only one Key, it functions correctly.

However, in this scenario, the output remains an array instead of individual values.

Do you have any suggestions on how I can properly split this into separate values?

Ideally, I want to transform this:

Product Names: Product Name 1, Product Name 2, Product Name 3

into an output like this:

Product Name 1

Product Name 2

Product Name 3

 

I intend to add these to a Google Docs document that has:

{{productname1}}

{{productname2}}

{{productname3}}

Therefore, I require the output of each value individually, not as a single array. I'm uncertain if my explanation is clear 🙁

This is precisely what I was searching for and required today. I would also appreciate seeing this incorporated into the already excellent Formatter, which I utilize extensively daily.

 
Posted : 22/11/2022 12:00 am
brianball
(@brianball)
Posts: 1
New Member
 

Please add my vote to support proper line item input in the Input Data fields for the Code by callin.io Actions.

 
Posted : 24/11/2022 12:00 am
JammerS
(@jammers)
Posts: 32
Eminent Member
 

Hi

 

I’ve added your vote for this feature request and we’ll be sure to keep you and the thread updated if this gets implemented.

 
Posted : 24/11/2022 12:00 am
joellabes
(@joellabes)
Posts: 1
New Member
 

Appreciate the workaround! It would be great to have this feature supported natively as well 🙏

 
Posted : 26/01/2023 12:00 am
JammerS
(@jammers)
Posts: 32
Eminent Member
 

Hi

I’ve added your vote for this feature request and we’ll be sure to keep you and the thread updated if this gets implemented.

 
Posted : 26/01/2023 12:00 am
AllanBettarel
(@allanbettarel)
Posts: 1
New Member
 

Appreciate the workaround! 

 

Any updates on this feature? If not, it would be great to see this implemented natively as well. 

 
Posted : 28/06/2023 12:00 am
stevebauman
(@stevebauman)
Posts: 1
New Member
 

I recently encountered this issue while trying to process complex array data (from a GraphQL request) received via a webhook in the JavaScript code step.

 

This behavior is quite unusual. Why not offer an option to utilize the entire decoded JSON response data within the inputData variable (or whatever data is supplying the step)? While I'm not privy to your backend specifics, from an external perspective, it seems like a lot of unnecessary overhead to post-process and flatten all arrays into a CSV, then present them in a frontend select list, map them to key-value pairs, and finally inject them into the code script.

 

An option to directly access all the decoded JSON data without callin.io's post-processing would be a significant improvement. Developers with coding experience would have a much smoother workflow if they didn't have to rely on a GUI to manually map key-value pairs of their flattened and transformed data, only to then transform it *back* into an array by exploding it with a comma (or a custom delimiter) 🙃.

 

This workaround becomes impractical with any significant data complexity fed into the code step.

 
Posted : 29/06/2023 12:00 am
Page 1 / 2
Share: