Skip to content
How to repeat actio...
 
Notifications
Clear all

How to repeat actions in callin.io for a variable number of values

26 Posts
8 Users
0 Reactions
7 Views
chrisboat
(@chrisboat)
Posts: 8
Active Member
 

RisoSystems - Thanks. That appears to be a great and viable solution. I can utilize the output record number from the trigger step to identify my current record.

The issue is that my input to the trigger step consists of a variable number of lines, so I don't have a number to compare against. It would fluctuate each time the callin.io was executed. The Only Continue IF trigger only permits a specific entered value in the conditional statement.

 
Posted : 27/09/2020 12:00 am
RisoSystems
(@risosystems)
Posts: 7
Active Member
 

I’m not sure I see that as an issue. When you execute the step that fetches the variable number of items (likely an array), simply append a variable to the output that represents the array's size:

var someArray = [‘John’, ‘Mary’, ‘Fred’, ‘pizza’];

var arraySize = someArray.length;

var arrayLimit = arraySize - 1;

output = [{someArray: someArray, arrayLimit: arrayLimit}];

I’m detailing all my steps here; naturally, this could be optimized for brevity. However, in your filter statement, compare the arrayLimit variable with the index variable, and you’ll achieve your goal.

 
Posted : 27/09/2020 12:00 am
chrisboat
(@chrisboat)
Posts: 8
Active Member
 

I've been utilizing your code with great success but have encountered an issue. The input data is presented below. The problem is that the last entry in 'Quantity' and 'Flavour' is being associated with the first empty entry instead of 'Product Foil' as intended. The output is also displayed.

I would appreciate your insights on this matter.

Image: 2839f828 1b9f 448c 881c bde30dbb875e
Image: 53a36d6f 40cb 45a4 b098 a3a94a967d4e
Image: 3a585c28 d586 4f56 a3a9 eac9ba433d16

 

 
Posted : 28/09/2020 12:00 am
RisoSystems
(@risosystems)
Posts: 7
Active Member
 

Could you please provide a mockup of the expected output using the data that has been supplied?

Is this what you are anticipating (with fewer headers):
 

Need Update Quantity Flavour
none    
none    
Foil   vanilla
none 6  
 
Posted : 28/09/2020 12:00 am
chrisboat
(@chrisboat)
Posts: 8
Active Member
 

Thank you very much for the prompt response.

The issue is that when a CSV line has empty values between commas, the code step incorrectly assigns the subsequent value.

Consequently, the quantity and flavor were both assigned to record 1, even though they belonged to record 3.

Apologies, the third image I shared previously seems to have added to the confusion.

What I require is the following:

 

 

Product Quantity Flavour
none    
none    
Foil 6 vanilla
none    

 

Thanks again

Chris

 
Posted : 28/09/2020 12:00 am
chrisboat
(@chrisboat)
Posts: 8
Active Member
 

I thought this might clarify what I'm aiming for.

Logs:

0

INFO [ { Product: '', recordNumber: 1, Quantity: '', Flavour: '' }, { Product: '', recordNumber: 2, Quantity: '', Flavour: '' }, { Product: 'Foil', recordNumber: 3, Quantity: '6', Flavour: 'Vanilla' }, { Product: '', recordNumber: 4, Quantity: '', Flavour: '' } ]

 
Posted : 28/09/2020 12:00 am
RisoSystems
(@risosystems)
Posts: 7
Active Member
 

Chrisboat,

I believe the issue lies within your data manipulation in the code step. I recommend copying your current code to a secure location and replacing it with the following:

This code generates an array of objects, which should trigger another branch. Each branch will receive a single object containing three properties: product, quantity, and flavour. Using these objects, you should be able to construct the desired lines in your spreadsheet.

Naturally, I cannot test this myself, but if you paste it in (with the initial substitutions), it ought to function correctly.

// These were solely for my syntax testing. Please utilize the inputData variables within your code:
// 
// Let Product = inputData.Product;
// Let Quantity = inputData.Quantity;
// Let Flavour = inputData.Flavour;
//
let Product = ['none', 'none', 'Foil', 'none'];
let Quantity = [null, null, 6, null];
let Flavour = [null, null, 'vanilla', null];
//
// As you can see below, this is my intended approach. While not the only method, it should be effective.
//
var LineItem = {};
var LineOuts = [];

let LineCount = Product.length;

for (var i = 0; i < LineCount; i++){  
    LineItem.product = Product;
  LineItem.quantity = Quantity;
  LineItem.flavour = Flavour;
  LineOuts = LineItem;
  LineItem = {};
    }

output = [{LineOuts : LineOuts}];

 

 

 
Posted : 28/09/2020 12:00 am
RisoSystems
(@risosystems)
Posts: 7
Active Member
 

One other thing. If the subsequent step doesn’t handle the objects well, then JSON.stringify the object before placing it in the array:

for (var i = 0; i < LineCount; i++){  
    LineItem.product = Product;
  LineItem.quantity = Quantity;
  LineItem.flavour = Flavour;
  LineOuts = JSON.stringify(LineItem);
  LineItem = {};
    }

The variable would have to be parsed before use in the spreadsheet:

let LineItemString = inputData.LineItem;
let LineItem = JSON.parse(LineItemString);

 

 
Posted : 28/09/2020 12:00 am
chrisboat
(@chrisboat)
Posts: 8
Active Member
 

HI,

I believe there's been some confusion regarding my recent post about a fork within a fork. My apologies to RicoSystems for any confusion caused. I need to resolve an issue with Tim’s fork code first, and then I will address the fork within a fork.

 

Tim’s fork code issue.

I've been utilizing your code with great success but have encountered a problem. The input data is presented below. The issue is that the first non-blank entry in Quantity and Flavour is being associated with the first record's 'none' entry for Product, instead of the 'Foil' entry in the third record, as it should be. The output is also shown.

What's occurring is that if a CSV line has no value between commas, the code step selects the next available value.

In this scenario, both the quantity and flavour were moved to record 1 when they were actually associated with record 3.

What I need is:

 

 

Product Quantity Flavour
none    
none    
Foil 6 vanilla
none  

 

 

What the output should look like:

logs

0

INFO [ { Product: '', recordNumber: 1, Quantity: '', Flavour: '' }, { Product: '', recordNumber: 2, Quantity: '', Flavour: '' }, { Product: 'Foil', recordNumber: 3, Quantity: '6', Flavour: 'Vanilla' }, { Product: '', recordNumber: 4, Quantity: '', Flavour: '' } ]

Input data and the output of the current behavior:

Image: 2839f828 1b9f 448c 881c bde30dbb875e
Image: 53a36d6f 40cb 45a4 b098 a3a94a967d4e
 
Posted : 28/09/2020 12:00 am
RisoSystems
(@risosystems)
Posts: 7
Active Member
 

Actually, the same code approach I shared applies to both scenarios. However, I will step back unless my name is featured prominently in a post.

 

 
Posted : 28/09/2020 12:00 am
chrisboat
(@chrisboat)
Posts: 8
Active Member
 

RisoSystems,

I must apologize. My previous post may not have been communicated clearly.

When I realized the recent responses to this current issue were from you (I had assumed it was Tim, I should have checked) and then saw that you were discussing a fork within a fork, I mistakenly assumed your reply pertained to my earlier topic about double forks. I am very grateful for the assistance you've provided. Much of this javascript code is beyond my understanding.

So please don't think I'm unwilling to accept help. I was concerned I might be confusing everyone and didn't want to be a burden. It appeared to me that my current problem with missing values between commas was related to Tim’s code, which is why I specifically asked him. If you are willing to help, I would truly appreciate it. 

This is what my input data actually looks like. I execute this code step, and then I run yours.

Image: a53ff1b9 8abb 4105 9449 60fd143ea775

When I attempted to use your code with my data, this is what I received. 

Image: be665d49 2858 4644 8a7b 081a969c38df

Thank you

Chris

 
Posted : 28/09/2020 12:00 am
Page 2 / 2
Share: