Zapier动作代码:Python input_data []从列表中剥离空值 [英] Zapier Action Code: Python input_data[] stripping nulls from list
问题描述
我一直在尝试使用Python为Zapier创建自定义代码.
I have been trying to create custom code for Zapier using Python.
该代码从Magento 2发票中提取了两个列表.它们是订单项的详细信息,我们使用数据来更新库存系统上的库存.不幸的是,捆绑产品会显示子产品,我需要将子产品的数量归零,这样也就不会从库存中移除它们.
The code pulls in two lists from a Magento 2 invoice. They are details from the line items, we use the data to update inventory on our stock system. The unfortunate thing is bundled products display the child products and I need to zero out the quantity for the child products so they don't get removed from stock as well.
如果父级是捆绑销售",我有逻辑地将库存项目数量设置为零.
I have the logic all sorted to set the stock items quantity to zero if the parent is a "bundle".
问题在于提取输入数据.空值将被丢弃.
The problem is pulling the input data. Nulls are being dropped.
例如,如果列表为null,null,null,则将结果捆绑在一起如果列表是1,1,1,null我最终得到的就是1,1,1
Eg if the list is null, null, null, bundle the result is just bundle if the list is 1,1,1,null all I end up with is 1,1,1
有没有办法在不删除空值的情况下从输入数据字段中提取数据?
Is there any way to pull the data from Input Data fields without removing the null values?
此刻的代码看起来像这样.
The code looks like this at the moment.
# if the product is a child of a bundle then zero out the quantity or it will take extra stock
quantity = str(input_data["item_qty_invoiced"])
quantity_array = quantity.split(",")
cleaned_quantity_list = ""
product_type = str(input_data["item_product_type"])
product_type_array = product_type.split(",")
num_of_line_items = len(product_type_array)
index = 0
while index < num_of_line_items:
if product_type_array[index] == "bundle":
quantity_array[index] = 0
index += 1
cleaned_quantity_list = ",".join(str(i) for i in quantity_array)
return {'item_qty_invoiced': cleaned_quantity_list}
我还没有尝试过javascript,但是很高兴看到它是一种选择.
I haven't tried javascript just yet, but am happy to look at that if it's an option.
推荐答案
根据Zapier于2019年3月 answer 开发人员,将输入强制转换为字符串的方式是固定的,并且没有解决此问题的计划.
According to a March 2019 answer by a Zapier dev, the way inputs are coerced into strings is fixed, and there were no plans to resolve this issue.