Remove Blank/Empty/Null Values from Array of Line Items Using Code

  • 19 January 2022
  • 11 replies
  • 1832 views
Remove Blank/Empty/Null Values from Array of Line Items Using Code
Userlevel 7
Badge +14

📌  We do our best to ensure that the code in these articles works as advertised, but please be aware that Zapier Support does not officially help with code steps due to their advanced nature. Feel free to comment on the article or ask in the Zapier Community, where we have code-savvy folks (including the author of this post).

QEver wanted to remove blank/empty/null values from an array of line items?
A: Use a Code app as a Zap step: https://zapier.com/apps/code/help

 

Code step configuration using JavaScript

NOTE: Map your line items array to the right side value for the “Set” Input Data variable in place of “A,,B,,C”.

 

 

Copy the Code

let Set = inputData.Set.split(","); // creates array by splitting Input Data variable at commas

Set = Set.filter(i => i); // filter out blank/empty/null values

output = [{Set}];

 

Results

Code step results WITHOUT filtering blank/empty/null values from an array of line items:

 

Code step results WITH filtering blank/empty/null values from an array of line items:

 

 

Contribution by Troy Tessalone

Troy is a Certified Zapier Expert who automates workflows with no-code and low-code apps to help clients save time and make money.


11 replies

How can i filter out any line items that where Line Total = 0 

 

Unfortunately this script doesn’t appear to work :(  Had thought I had found a solution for removing any blanks in my array - although it could be that the ,, don’t actually have an empty field as there is no space as such

Userlevel 7
Badge +14

@boomerang 

We’d need to see detailed screenshots with how each of your Zap steps is configured along with the Zap JavaScript Code in order to be able to evaluate and advise.

@Troy Tessalone here is the screenshot of the code.


The zap starts with Pandadoc completed and pulls in the relevant information, which are in arrays.

The next steps is in Katana to Find a customer and if it doesn’t exist to create the customer

Next step is to ideally either remove the blank ,, but in reality this won’t marry up with the other arrays, so it would be preferable to replace the ,, to add the word NULL or a simply -

The last step is to create a Sales Order in Katana.

The reason we need to find a way to replace ,, with NULL or - is that the Sales Order creation won’t go ahead if that is blank.  Hope that helps.

 

 

I click Refresh fields and then continue and then test and the result is as follows as you can see there is an empty entry on line 69 - in fact this order should have 99 rows and only 86 rows are returned, so I am guessing the final rows did get removed.

 

If we could replace the ,, with ‘ - ‘ that would be great :)  Thanks in advance

Userlevel 7
Badge +14

@boomerang 

This help topic is related to: Remove Blank/Empty/Null Values from Array of Line Items Using Code

Your request is to: replace the ,, to add the word NULL or a simply -

 

If you are interested in custom Code, please send me a DM.

@Troy Tessalone thank you for such decision!

Currently as a result of the Code step I have a comma separated line of data?
Could you help me to have a result of the code step as a vertical list of data?

This is my Code step:


Here is the result I’m getting:
 


​​​​​​​Thank you in advance!

@Troy Tessalone did it by updating your code like this:
 

let Set = inputData.Set.split(","); // creates array by splitting Input Data variable at commas

Set = Set.filter(i => i); // filter out blank/empty/null values

const values = Set.join("\n");

output = { values };
 

Userlevel 7
Badge +14

@Ramil Milzidinov 

Are you indicating that you’ve solved your issue?

@Troy Tessalone  yes, thanks

@Troy Tessalone 

This is a great help however we have 2 values in line items (SKU and QTY) and want to ignore an entire line if SKU is blank.

For example:

SKU: ABC123,,BCD321

QTY: 1,1,1,2

Line items 1 and 4 should be included but line items 2 and 3 should be excluded.  Is there an easy way to do this?

Thanks heaps :)

 

Userlevel 7
Badge +14

Hi @Scott123 

If you’re looking for custom code, then I can be hired: https://zapier.com/experts/automation-ace

Reply