Question

How to create 2 different line item group and putting it together? Array within Array using Input Designer or Code Mode.

  • 1 September 2022
  • 5 replies
  • 32 views

Userlevel 1

Hi All,

 

Does anybody know how to put a line item group within a line item?

 

Here is the sample of the code that I need to duplicate in Developer Zapier,

 

items: [
{
item_number: 2,
item_name: 'Delivery1',
quantity: 1,
unit_of_measure: 'pieces',
unit_price: 100,
net_price: 100,
tax_breakdown: [{regime: 'VAT', rate: 27, amount: 27}]
}
]

 

Line “tax_breakdown” has another array. In a nutshell within Input Designer, I would need to create an array within an array. Is this possible? Or is this confusing?

 

Thank you and appreciate the help!


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

5 replies

Userlevel 3
Badge +6

Hi @joshua.lim !

Hm, well, there’s no way to do that in the input designer. And according to the schema, there’s no reason you couldn’t put fields with children (line item groups) inside other fields with children in a CLI version of your app.

You could try that and see if it works in the editor, but you might run into problems.

So that tax_breakdown field could take multiple items in it? Does it need to always take multiple items, or can you imagine an MVP of the integration you’re building where it always only takes one item?

Maybe we could take a step back and consider what you’re trying to do here. This is in an action (i.e., not a trigger) you’re trying to do this? And where is the data that users will be mapping this from? Are they getting it from an upstream app, or are you thinking they’ll be building it manually?

Let me know...I’ll keep an eye out for your replies!

Userlevel 1

Hi @shalgrim ,

 

Thank you very much for your reply and help with this. I really appreciate it! 

 

A bit of background, I am not really an engineer or well versed in Javascript. What I am currently doing is just bridging Zapier into another app. I do not own this app. I believe it will always need to take multiple items.

 

Yes, this is in action not a trigger. It is sort of like creating Invoices. The users will be mapping the data themselves, meaning they will be filling out the information. 

 

Also, I do not know how to do a CLI. I did read about it and it looks as though I could build in it. However I am not yet so advanced in this.

 

Thank you again for your help!

Userlevel 3
Badge +6

Thanks for that detail, @joshua.lim ! 

Even outside of CLI, I think you could probably accomplish what you want with code mode, though I think it would require some engineering-level hack where you eschew line items and require the input data to be in a very specific format that your code mode is expecting.

Hope that helps!

Userlevel 1

Hi Shalgrim,

 

Hope you had a great weekend! Thank you! I will try and figure it out.

 

Right now this is the code I am using and also it only allows me to create one item. I will definitely explore more. I really appreciate the help!

 

 

const options = {
    url: 'https://api.fonoa.com/reporting/v2/transactions',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Ocp-Apim-Subscription-Key':'{{bundle.authData.Ocp-Apim-Subscription-Key}}'
    },
    body: JSON.stringify({
        "meta": {
            "country_code": bundle.inputData.country_code,
            "language_code": bundle.inputData.language_code,
            "invoice_scenario": bundle.inputData.invoice_scenario,
            "currency_code": bundle.inputData.currency_code
        },
        "supplier": {
            "id": bundle.inputData.supplier_id
        },
        "customer": {
            "id": bundle.inputData.customer_id
        },
        "invoice_type": bundle.inputData.invoice_type,
        "transaction_date": bundle.inputData.transaction_date,
        "total_net_amount": bundle.inputData.total_net_amount,
        "total_tax_amount": bundle.inputData.total_tax_amount,
        "total_amount": bundle.inputData.total_amount,
        "items": [
            {
                "item_number": bundle.inputData.item_number,
                "item_name": bundle.inputData.item_name,
                "item_type": bundle.inputData.item_type,
                "item_code": bundle.inputData.item_code,
                "description": bundle.inputData.item_description,
                "quantity": bundle.inputData.item_quantity,
                "unit_price": bundle.inputData.item_unit_price,
                "net_price": bundle.inputData.item_net_price,
                "tax_breakdown": [
                    {
                        "regime": bundle.inputData.tax_breakdown_regime,
                        "rate": bundle.inputData.tax_breakdown_rate,
                        "amount": bundle.inputData.tax_breakdown_amount,
                        "type": bundle.inputData.tax_breakdown_type,
                        "code": bundle.inputData.tax_breakdown_code
                    }
                ]
            }
        ],
        "payments": [
            {
                "payment_type": bundle.inputData.payment_type,
                "amount": bundle.inputData.payment_amount
            }
        ]
    })
    };

  
  return z.request(options)
    .then((response) => {
      response.throwForStatus();
      const results = response.json;
  
      // You can do any parsing you need for results here before returning them
  
      return results;
    });

Userlevel 3
Badge +6

Got it. So what I’m thinking is that you need to assume that tax_breakdown_regime, tax_breakdown_rate, etc. will all accept lists of values where they are separated by commas. So, for example, if somebody wanted two “tax breakdowns” they’d have to enter something like this into their fields:

 

tax_breakdown_regime: regime1,regime2

tax_breakdown_rate: .05,.10

tax_breakdown_amount: 20,30

tax_breakdown_type: full,partial

tax_breakdown_code: A35,B99

 

Then you could do something like:

const breakdowns = [];

for (let i = 0; i < tax_breakdown_regime.split(‘,’).length; i++) {

const breakdown = {

rate: tax_breakdown_rate.split(',')[i],

 amount = tax_breakdown_amount.split(',')[i],

 code = tax_breakdown_code.split(',')[i],

 type = tax_breakdown_type.split(',')[i],

regime: tax_breakdown_regime.spit(',')[i]

 };

breakdowns.push(breakdown):

}

 

Then in the options assignment you’re doing you’d assign “tax_breakdowns”: breakdowns

That’s going to break down (pun intended) if your data could include commas (we can pick a different delimiter) or somebody enters a different number of regimes than rates, but it’s a start.

Let me know how it goes!