Get specific bundle from Array

Hey everyone,

I’m currently trying to filter out a specific product from an array in Pipedrive (List Product in Deals). Since Pipedrive doesn’t have a function to provide an overall discount, we created a product called “Discount” for that purpose. I would like to calculate the percentage discount every time this product is included in a deal. However, I need to filter out this specific product from the bundles. How can I do that and include the percentage discount on an invoice?

I hope you understand what I mean!


Hi Jens.

Could you provide a sample scenario showing what you mean, and showing the output of the List Product in Deals module with your data (suitably redacted of course)?

1 Like

Hey @DavidGurr_Make,

here is an example, the bundle 3 is the discount. With this data, I then create invoice items, but I would like to filter out the “Sonderrabatt” and insert the calculated percentage discount into the “discount” field in the invoicing tool.

Thanks for that.

And how are you creating the invoice?

1 Like

Attached you can find the Array aggrigator for the invoice positions. In Discount I want to calculate the overall discount like: (Discount amount)/(Sum of Deal + Discount amount)

Hi @Jens,

Do let me know if this makes sense, What you need to do is(assuming that the discount will always be a single entry),

First Approach

  1. After the Search/List Line Item/Invoice Module, Add an Array Aggregator, in which you will have to use Select All Since we will just be grabbing the data we get from the previous module
  2. After which put an Iterator which we will use to iterate over the Array Aggregator you get from the previous step
  3. Put an Array aggregator again to do the same that you are currently doing with Destination Data Structure enabled
  4. Put a filter in between the Step 2. Iterator and Step 3 Aggregrator, to filter out the Discount Line Item

Now, for the discount part needed in Step 3) You can use the following formula, which will give you the discount value,


Not sure, if the sum is the correct discount value that you want to grab but you can change it to other value if required.

You can use this formula to calculate the discount for line items as required in the aggregator mapping.

Second Approach

Not sure if this makes sense, but this will be an easier option if this is feasible. What you can do is add two List Product in Deals.

  1. Liist Product Deals, Put a Filter in between, and/or add an array aggregator or set a Variable Module. Filter will be used to pick up the Discount Line Item, you can just do this if name is Sonderrabatt then go to set the variable or array aggregator
  2. Now Keep the rest of the module as it is that you have at the moment, just like do the same List Product in Deals, add a filter in between to remove the discount line item, and do the array aggregator you have at the moment.
  3. Use the result from Step 1 to calculate the discount

Hey @Runcorn,

Thank you very much for your help. The second option with a variable worked perfectly! Actually quite simple, haha.

Thank you!

@Runcorn Okay, now I’ve noticed something. Of course, if there is no special discount product in the deal, the automation stops at the filter. How can we best get around that?

This might work … add a Router and set the Discount variable only when the item is a discount line.

Set the other Router path as the fallback path in the filter. You’ll need to Get the value of the Discount variable (otherwise it’s not available as it was in the other path).

You may need to set the Discount variable to zero too, before the Router … I’ve not tried executing this.

Here’s an example using Google Sheets instead of Pipedrive:


The only problem I see with this is, the ordering of the discount line item as part of the response.

Which, Approach did you use? It won’t be a problem in either of the flow, cause using aggregator will ensure that the flow will continue regardless of the result.

@DavidGurr_Make Good idea! But now, if I have three products, three invoices are also created and the discount is only applied to one. How can I get around this? Sorry for the dumb questions!

Are you aiming to apply the discount individually to each line item, or to the whole invoice?

Also, I don’t think you need to have the List Products in a Deal module twice - you may be able to have the first one as the Array Aggregator source.

@DavidGurr_Make Yes, you are right. Now it looks like this:

I would like to enter the discount on each invoice line item, so I would only need the variable once and not twice like now in this example above. Here you can see what the array aggregator for the invoice items looks like:

Hi @Jens,

Is the Discount item always the first bundle? Or the first item in the List Products and Deals? If yes, then the one above will work just fine regardless of the Get Variable execution, what it does currently is set if there is a discount, and then for other line items it will just use the Set Variable value that you are using on lower route.

1 Like

No, is unfortunately different, mostly at the end, but can also be at the beginning. So is unfortunately now once the variable with 0 and once with the discount (5000). The aggregator then unfortunately takes the 0 €.

Basically, this flow you have works,


What you need to is change the approach for this, So just structure your scenario to look like this instead of one you have,


YES! Now it works, this is the solution @Runcorn :slightly_smiling_face:

Thank you both so much! @DavidGurr_Make @Runcorn