Zapier动作代码:Python input_data []从列表中剥离空值 [英] Zapier Action Code: Python input_data[] stripping nulls from list

查看:43
本文介绍了Zapier动作代码:Python input_data []从列表中剥离空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用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.

一个

最好的办法是制作一个小型CLI应用程序,该程序可复制twitter操作.然后,您可以将输出设置为json字符串,我们不会碰它.我已经在几个地方做到了这一点,并且效果很好(除了额外的负担,当我们需要为您处理Twitter时,必须自己与Twitter交互)

the best thing to do is make a little CLI app that replicates the twitter action. Then you can set the output to be a json string and we won't touch it. I've done this in a couple of places and it works great (outside the added burden of having to interface with twitter yourself when we should take care of that for you)

这确实打败了使用Zapier的目的的一半.

This does defeat half the purpose of using Zapier though.

这篇关于Zapier动作代码:Python input_data []从列表中剥离空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆